breezedeus commited on
Commit
255fbb0
·
1 Parent(s): 21d5ed5

Update to v2.3.2. Refactor detection model handling in app.py; update requirements for cnocr and numpy

Browse files
Files changed (2) hide show
  1. app.py +16 -17
  2. requirements.txt +3 -272
app.py CHANGED
@@ -34,6 +34,12 @@ from cnocr.utils import set_logger, draw_ocr_results, download
34
  logger = set_logger()
35
  MODELS = {}
36
 
 
 
 
 
 
 
37
 
38
  def plot_for_debugging(rotated_img, one_out, box_score_thresh, crop_ncols, prefix_fp):
39
  import matplotlib.pyplot as plt
@@ -73,8 +79,7 @@ def get_ocr_model(det_model_name, rec_model_name, det_more_configs):
73
  if (det_model_name, rec_model_name, config_str) in MODELS:
74
  return MODELS[(det_model_name, rec_model_name, config_str)]
75
 
76
- det_model_name, det_model_backend = det_model_name.split('::')
77
- # rec_model_name, rec_model_backend = rec_model_name.split('::')
78
  rec_model_backend = 'onnx'
79
  model = CnOcr(
80
  det_model_name=det_model_name,
@@ -157,7 +162,6 @@ def recognize(
157
  min_box_size=min_box_size,
158
  )
159
 
160
- det_model_name, det_model_backend = det_model_name.split('::')
161
  if is_single_line or det_model_name == 'naive_det':
162
  out_texts = visualize_naive_result(
163
  img, det_model_name, ocr_out, box_score_thresh
@@ -183,11 +187,6 @@ def recognize(
183
 
184
 
185
  def main():
186
- det_models = list(DET_AVAILABLE_MODELS.all_models())
187
- det_models.append(('naive_det', 'onnx'))
188
- det_models.sort()
189
- det_models = [f'{m}::{b}' for m, b in det_models]
190
-
191
  all_models = list(REC_AVAILABLE_MODELS.all_models())
192
  all_models = [f'{m}' for m, b in all_models if b == 'onnx']
193
  cnocr_models = [name for name in all_models if 'densenet' in name]
@@ -206,7 +205,7 @@ def main():
206
  )
207
  example_func = functools.partial(
208
  recognize,
209
- # det_model_name='ch_PP-OCRv3_det::onnx',
210
  rotated_bbox=True,
211
  # use_angle_clf=False,
212
  new_size=768,
@@ -215,49 +214,49 @@ def main():
215
  )
216
  examples = [
217
  [
218
- 'ch_PP-OCRv3_det::onnx',
219
  True,
220
  'number-densenet_lite_136-fc',
221
  False,
222
  'docs/examples/card1-s.jpg',
223
  ],
224
  [
225
- 'ch_PP-OCRv3_det::onnx',
226
  True,
227
  'number-densenet_lite_136-fc',
228
  False,
229
  'docs/examples/card2-s.jpg',
230
  ],
231
  [
232
- 'ch_PP-OCRv3_det::onnx',
233
  True,
234
  'number-densenet_lite_136-fc',
235
  False,
236
  'docs/examples/cy1-s.jpg',
237
  ],
238
  [
239
- 'ch_PP-OCRv3_det::onnx',
240
  False,
241
  'densenet_lite_136-gru',
242
  False,
243
  'docs/examples/huochepiao.jpeg',
244
  ],
245
  [
246
- 'ch_PP-OCRv3_det::onnx',
247
  False,
248
  'densenet_lite_136-gru',
249
  False,
250
  'docs/examples/1_res.jpg',
251
  ],
252
  [
253
- 'db_shufflenet_v2::pytorch',
254
  False,
255
  'en_number_mobile_v2.0',
256
  False,
257
  'docs/examples/en_book1.jpeg',
258
  ],
259
  [
260
- 'db_shufflenet_v2::pytorch',
261
  False,
262
  'densenet_lite_136-gru',
263
  True,
@@ -291,7 +290,7 @@ def main():
291
  with gr.Column(min_width=200, variant='panel', scale=3):
292
  gr.Markdown('### 模型设置')
293
  det_model_name = gr.Dropdown(
294
- label='选择检测模型', choices=det_models, value='ch_PP-OCRv3_det::onnx',
295
  )
296
  is_single_line = gr.Checkbox(label='单行文字模式(不使用检测模型)', value=False)
297
 
 
34
  logger = set_logger()
35
  MODELS = {}
36
 
37
+ DET_MODELS = list(DET_AVAILABLE_MODELS.all_models())
38
+ DET_MODELS.append(('naive_det', 'onnx'))
39
+ DET_MODELS.sort()
40
+ DET_MODELS_NAME = [f'{m}' for m, _ in DET_MODELS]
41
+ DET_MODELS_DICT = {f'{m}': f'{b}' for m, b in DET_MODELS}
42
+
43
 
44
  def plot_for_debugging(rotated_img, one_out, box_score_thresh, crop_ncols, prefix_fp):
45
  import matplotlib.pyplot as plt
 
79
  if (det_model_name, rec_model_name, config_str) in MODELS:
80
  return MODELS[(det_model_name, rec_model_name, config_str)]
81
 
82
+ det_model_backend = DET_MODELS_DICT[det_model_name]
 
83
  rec_model_backend = 'onnx'
84
  model = CnOcr(
85
  det_model_name=det_model_name,
 
162
  min_box_size=min_box_size,
163
  )
164
 
 
165
  if is_single_line or det_model_name == 'naive_det':
166
  out_texts = visualize_naive_result(
167
  img, det_model_name, ocr_out, box_score_thresh
 
187
 
188
 
189
  def main():
 
 
 
 
 
190
  all_models = list(REC_AVAILABLE_MODELS.all_models())
191
  all_models = [f'{m}' for m, b in all_models if b == 'onnx']
192
  cnocr_models = [name for name in all_models if 'densenet' in name]
 
205
  )
206
  example_func = functools.partial(
207
  recognize,
208
+ # det_model_name='ch_PP-OCRv3_det',
209
  rotated_bbox=True,
210
  # use_angle_clf=False,
211
  new_size=768,
 
214
  )
215
  examples = [
216
  [
217
+ 'ch_PP-OCRv3_det',
218
  True,
219
  'number-densenet_lite_136-fc',
220
  False,
221
  'docs/examples/card1-s.jpg',
222
  ],
223
  [
224
+ 'ch_PP-OCRv3_det',
225
  True,
226
  'number-densenet_lite_136-fc',
227
  False,
228
  'docs/examples/card2-s.jpg',
229
  ],
230
  [
231
+ 'ch_PP-OCRv3_det',
232
  True,
233
  'number-densenet_lite_136-fc',
234
  False,
235
  'docs/examples/cy1-s.jpg',
236
  ],
237
  [
238
+ 'ch_PP-OCRv3_det',
239
  False,
240
  'densenet_lite_136-gru',
241
  False,
242
  'docs/examples/huochepiao.jpeg',
243
  ],
244
  [
245
+ 'ch_PP-OCRv3_det',
246
  False,
247
  'densenet_lite_136-gru',
248
  False,
249
  'docs/examples/1_res.jpg',
250
  ],
251
  [
252
+ 'db_shufflenet_v2',
253
  False,
254
  'en_number_mobile_v2.0',
255
  False,
256
  'docs/examples/en_book1.jpeg',
257
  ],
258
  [
259
+ 'db_shufflenet_v2',
260
  False,
261
  'densenet_lite_136-gru',
262
  True,
 
290
  with gr.Column(min_width=200, variant='panel', scale=3):
291
  gr.Markdown('### 模型设置')
292
  det_model_name = gr.Dropdown(
293
+ label='选择检测模型', choices=DET_MODELS_NAME, value='ch_PP-OCRv3_det',
294
  )
295
  is_single_line = gr.Checkbox(label='单行文字模式(不使用检测模型)', value=False)
296
 
requirements.txt CHANGED
@@ -6,278 +6,9 @@
6
  #
7
  --extra-index-url https://pypi.org/simple
8
 
9
- aiohttp==3.8.4
10
- # via fsspec
11
- aiosignal==1.3.1
12
- # via aiohttp
13
- albumentations==1.3.1
14
- # via -r requirements.in
15
- appdirs==1.4.4
16
- # via wandb
17
- async-timeout==4.0.2
18
- # via aiohttp
19
- attrs==23.1.0
20
- # via aiohttp
21
- certifi==2023.5.7
22
- # via
23
- # requests
24
- # sentry-sdk
25
- charset-normalizer==3.1.0
26
- # via
27
- # aiohttp
28
- # requests
29
- click==8.1.3
30
- # via
31
- # -r requirements.in
32
- # cnstd
33
- # wandb
34
- cnstd>=1.2.3.4
35
- # via -r requirements.in
36
- coloredlogs==15.0.1
37
- # via onnxruntime
38
- contourpy==1.1.0
39
- # via matplotlib
40
- cycler==0.11.0
41
- # via matplotlib
42
- docker-pycreds==0.4.0
43
- # via wandb
44
- filelock==3.12.2
45
- # via
46
- # huggingface-hub
47
- # torch
48
- flatbuffers==23.5.26
49
- # via onnxruntime
50
- fonttools==4.40.0
51
- # via matplotlib
52
- frozenlist==1.3.3
53
- # via
54
- # aiohttp
55
- # aiosignal
56
- fsspec[http]==2023.6.0
57
- # via
58
- # huggingface-hub
59
- # pytorch-lightning
60
- gitdb==4.0.10
61
- # via gitpython
62
- gitpython==3.1.34
63
- # via wandb
64
- huggingface-hub==0.15.1
65
- # via cnstd
66
- humanfriendly==10.0
67
- # via coloredlogs
68
- idna==3.4
69
- # via
70
- # requests
71
- # yarl
72
- imageio==2.31.3
73
- # via scikit-image
74
- importlib-resources==5.12.0
75
- # via matplotlib
76
- jinja2==3.1.2
77
- # via torch
78
- joblib==1.3.2
79
- # via scikit-learn
80
- kiwisolver==1.4.4
81
- # via matplotlib
82
- lazy-loader==0.3
83
- # via scikit-image
84
- lightning-utilities==0.9.0
85
- # via pytorch-lightning
86
- markupsafe==2.1.3
87
- # via jinja2
88
- matplotlib==3.7.1
89
- # via
90
- # cnstd
91
- # seaborn
92
- mpmath==1.3.0
93
- # via sympy
94
- multidict==6.0.4
95
- # via
96
- # aiohttp
97
- # yarl
98
- networkx==3.1
99
- # via
100
- # scikit-image
101
- # torch
102
- numpy==1.25.0
103
- # via
104
- # -r requirements.in
105
- # albumentations
106
- # cnstd
107
- # contourpy
108
- # imageio
109
- # matplotlib
110
- # onnx
111
- # onnxruntime
112
- # opencv-python
113
- # opencv-python-headless
114
- # pandas
115
- # pytorch-lightning
116
- # pywavelets
117
- # qudida
118
- # scikit-image
119
- # scikit-learn
120
- # scipy
121
- # seaborn
122
- # shapely
123
- # tifffile
124
- # torchmetrics
125
- # torchvision
126
- onnx==1.14.0
127
- # via
128
- # -r requirements.in
129
- # cnstd
130
- onnxruntime==1.15.1
131
- # via
132
- # -r requirements.in
133
- # cnstd
134
- opencv-python==4.7.0.72
135
- # via cnstd
136
- opencv-python-headless==4.8.0.76
137
- # via
138
- # albumentations
139
- # qudida
140
- packaging==23.1
141
- # via
142
- # huggingface-hub
143
- # lightning-utilities
144
- # matplotlib
145
- # onnxruntime
146
- # pytorch-lightning
147
- # scikit-image
148
- # torchmetrics
149
- pandas==2.0.3
150
- # via
151
- # cnstd
152
- # seaborn
153
- pathtools==0.1.2
154
- # via wandb
155
- pillow==9.5.0
156
- # via
157
- # -r requirements.in
158
- # cnstd
159
- # imageio
160
- # matplotlib
161
- # scikit-image
162
- # torchvision
163
- polygon3==3.0.9.1
164
- # via cnstd
165
- protobuf==4.23.3
166
- # via
167
- # onnx
168
- # onnxruntime
169
- # wandb
170
- psutil==5.9.5
171
- # via wandb
172
- pyclipper==1.3.0.post4
173
- # via cnstd
174
- pyparsing==3.1.0
175
- # via matplotlib
176
- python-dateutil==2.8.2
177
- # via
178
- # matplotlib
179
- # pandas
180
- pytorch-lightning==2.0.8
181
- # via
182
- # -r requirements.in
183
- # cnstd
184
- pytz==2023.3
185
- # via pandas
186
- pywavelets==1.4.1
187
- # via scikit-image
188
- pyyaml==6.0
189
- # via
190
- # albumentations
191
- # cnstd
192
- # huggingface-hub
193
- # pytorch-lightning
194
- # wandb
195
- qudida==0.0.4
196
- # via albumentations
197
- requests==2.31.0
198
- # via
199
- # fsspec
200
- # huggingface-hub
201
- # torchvision
202
- # wandb
203
- scikit-image==0.21.0
204
- # via albumentations
205
- scikit-learn==1.3.0
206
- # via qudida
207
- scipy==1.11.1
208
- # via
209
- # albumentations
210
- # cnstd
211
- # scikit-image
212
- # scikit-learn
213
- seaborn==0.12.2
214
- # via cnstd
215
- sentry-sdk==1.30.0
216
- # via wandb
217
- setproctitle==1.3.2
218
- # via wandb
219
- shapely==2.0.1
220
- # via cnstd
221
- six==1.16.0
222
- # via
223
- # docker-pycreds
224
- # python-dateutil
225
- smmap==5.0.0
226
- # via gitdb
227
- sympy==1.12
228
- # via
229
- # onnxruntime
230
- # torch
231
- threadpoolctl==3.2.0
232
- # via scikit-learn
233
- tifffile==2023.8.30
234
- # via scikit-image
235
- torch==2.0.1
236
- # via
237
- # -r requirements.in
238
- # cnstd
239
- # pytorch-lightning
240
- # torchmetrics
241
- # torchvision
242
- torchmetrics==0.11.4
243
- # via
244
- # -r requirements.in
245
- # pytorch-lightning
246
- torchvision==0.15.2
247
- # via
248
- # -r requirements.in
249
- # cnstd
250
- tqdm==4.65.0
251
- # via
252
- # -r requirements.in
253
- # cnstd
254
- # huggingface-hub
255
- # pytorch-lightning
256
- typing-extensions==4.7.0
257
- # via
258
- # huggingface-hub
259
- # lightning-utilities
260
- # onnx
261
- # pytorch-lightning
262
- # qudida
263
- # torch
264
- # wandb
265
- tzdata==2023.3
266
- # via pandas
267
- unidecode==1.3.6
268
- # via cnstd
269
- urllib3==2.0.3
270
- # via
271
- # requests
272
- # sentry-sdk
273
- wandb==0.15.10
274
- # via -r requirements.in
275
- yarl==1.9.2
276
- # via aiohttp
277
- zipp==3.15.0
278
- # via importlib-resources
279
-
280
- cnocr==2.3.0.1
281
 
282
  # The following packages are considered to be unsafe in a requirements file:
283
  # setuptools
 
6
  #
7
  --extra-index-url https://pypi.org/simple
8
 
9
+ cnocr>=2.3.2.1,<2.4
10
+ opencv-python
11
+ numpy
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # The following packages are considered to be unsafe in a requirements file:
14
  # setuptools