cnocr 2.3.0.3__tar.gz → 2.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. {cnocr-2.3.0.3 → cnocr-2.3.1}/PKG-INFO +20 -4
  2. {cnocr-2.3.0.3 → cnocr-2.3.1}/README.md +19 -3
  3. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/__version__.py +1 -1
  4. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/app.py +1 -1
  5. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/cli.py +2 -2
  6. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/cn_ocr.py +5 -4
  7. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/consts.py +12 -0
  8. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/data_utils/transforms.py +12 -13
  9. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/dataset_utils.py +22 -12
  10. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/gradio_app.py +1 -1
  11. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/ppocr/__init__.py +1 -0
  12. cnocr-2.3.1/cnocr/ppocr/consts.py +78 -0
  13. cnocr-2.3.1/cnocr/ppocr/rapid_recognizer.py +135 -0
  14. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/utils.py +11 -10
  15. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr.egg-info/PKG-INFO +20 -4
  16. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr.egg-info/SOURCES.txt +1 -0
  17. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr.egg-info/requires.txt +2 -1
  18. {cnocr-2.3.0.3 → cnocr-2.3.1}/setup.py +2 -1
  19. cnocr-2.3.0.3/cnocr/ppocr/consts.py +0 -48
  20. {cnocr-2.3.0.3 → cnocr-2.3.1}/LICENSE +0 -0
  21. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/__init__.py +0 -0
  22. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/classification/__init__.py +0 -0
  23. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/classification/dataset.py +0 -0
  24. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/classification/image_classifier.py +0 -0
  25. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/clf_cli.py +0 -0
  26. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/data_utils/__init__.py +0 -0
  27. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/data_utils/aug.py +0 -0
  28. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/data_utils/block_shuffle.py +0 -0
  29. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/data_utils/utils.py +0 -0
  30. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/dataset.py +0 -0
  31. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/gradio_app2.py +0 -0
  32. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/label_cn.txt +0 -0
  33. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/label_number.txt +0 -0
  34. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/line_split.py +0 -0
  35. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/lr_scheduler.py +0 -0
  36. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/models/__init__.py +0 -0
  37. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/models/ctc.py +0 -0
  38. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/models/densenet.py +0 -0
  39. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/models/mobilenet.py +0 -0
  40. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/models/ocr_model.py +0 -0
  41. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/ppocr/postprocess/__init__.py +0 -0
  42. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/ppocr/postprocess/rec_postprocess.py +0 -0
  43. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/ppocr/pp_recognizer.py +1 -1
  44. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/ppocr/utility.py +0 -0
  45. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/ppocr/utils/__init__.py +0 -0
  46. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/ppocr/utils/chinese_cht_dict.txt +0 -0
  47. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/ppocr/utils/en_dict.txt +0 -0
  48. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/ppocr/utils/ppocr_keys_v1.txt +0 -0
  49. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/recognizer.py +0 -0
  50. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/serve.py +0 -0
  51. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr/trainer.py +0 -0
  52. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr.egg-info/dependency_links.txt +0 -0
  53. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr.egg-info/entry_points.txt +0 -0
  54. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr.egg-info/not-zip-safe +0 -0
  55. {cnocr-2.3.0.3 → cnocr-2.3.1}/cnocr.egg-info/top_level.txt +0 -0
  56. {cnocr-2.3.0.3 → cnocr-2.3.1}/setup.cfg +0 -0
  57. {cnocr-2.3.0.3 → cnocr-2.3.1}/tests/test_cnocr.py +0 -0
  58. {cnocr-2.3.0.3 → cnocr-2.3.1}/tests/test_dataset.py +0 -0
  59. {cnocr-2.3.0.3 → cnocr-2.3.1}/tests/test_models.py +0 -0
  60. {cnocr-2.3.0.3 → cnocr-2.3.1}/tests/test_ppocr.py +0 -0
  61. {cnocr-2.3.0.3 → cnocr-2.3.1}/tests/test_pytorch.py +0 -0
  62. {cnocr-2.3.0.3 → cnocr-2.3.1}/tests/test_trainer.py +0 -0
  63. {cnocr-2.3.0.3 → cnocr-2.3.1}/tests/test_transforms.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cnocr
3
- Version: 2.3.0.3
3
+ Version: 2.3.1
4
4
  Summary: Python3 package for Chinese/English OCR, with small pretrained models
5
5
  Home-page: https://github.com/breezedeus/cnocr
6
6
  Author: breezedeus
@@ -69,6 +69,16 @@ License-File: LICENSE
69
69
  ---
70
70
  </div>
71
71
 
72
+ ### [Update 2024.11.28]:发布 V2.3.1
73
+
74
+ 主要变更:
75
+
76
+ * 基于 RapidOCR 集成 PPOCRv4 最新版 OCR 模型,提供更多的模型选择
77
+ * 新增支持 PP-OCRv4 识别模型,包括标准版和服务器版
78
+ * 修改读文件实现方式,支持 Windows 的中文路径
79
+ * 修复Bug:当使用多个进程时,transform_func 无法序列化
80
+ * 修复Bug:与 albumentations=1.4.* 兼容
81
+
72
82
  ### [Update 2023.12.24]:发布 V2.3
73
83
 
74
84
  主要变更:
@@ -406,13 +416,13 @@ print(ocr_out)
406
416
  | ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ------------------------------ | -------------------- |
407
417
  | db_shufflenet_v2 | √ | X | cnocr | 18 M | 简体中文、繁体中文、英文、数字 | √ |
408
418
  | **db_shufflenet_v2_small** | √ | X | cnocr | 12 M | 简体中文、繁体中文、英文、数字 | √ |
409
- | [db_shufflenet_v2_tiny](https://mp.weixin.qq.com/s/fHPNoGyo72EFApVhEgR6Nw) | √ | X | cnocr | 7.5 M | 简体中文、繁体中文、英文、数字 | √ |
410
419
  | db_mobilenet_v3 | √ | X | cnocr | 16 M | 简体中文、繁体中文、英文、数字 | √ |
411
420
  | db_mobilenet_v3_small | √ | X | cnocr | 7.9 M | 简体中文、繁体中文、英文、数字 | √ |
412
421
  | db_resnet34 | √ | X | cnocr | 86 M | 简体中文、繁体中文、英文、数字 | √ |
413
422
  | db_resnet18 | √ | X | cnocr | 47 M | 简体中文、繁体中文、英文、数字 | √ |
423
+ | ch_PP-OCRv4_det | X | √ | ppocr | 4.5 M | 简体中文、繁体中文、英文、数字 | √ |
424
+ | ch_PP-OCRv4_det_server | X | √ | ppocr | 108 M | 简体中文、繁体中文、英文、数字 | √ |
414
425
  | ch_PP-OCRv3_det | X | √ | ppocr | 2.3 M | 简体中文、繁体中文、英文、数字 | √ |
415
- | ch_PP-OCRv2_det | X | √ | ppocr | 2.2 M | 简体中文、繁体中文、英文、数字 | √ |
416
426
  | **en_PP-OCRv3_det** | X | √ | ppocr | 2.3 M | **英文**、数字 | √ |
417
427
 
418
428
 
@@ -449,11 +459,18 @@ print(ocr_out)
449
459
  | **number-densenet_lite_136-fc** 🆕 | √ | √ | cnocr | 2.7 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
450
460
  | **number-densenet_lite_136-gru** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 5.5 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
451
461
  | **number-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://gf.bilibili.com/item/detail/1104055055)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 55 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
462
+ | ch_PP-OCRv4 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
463
+ | ch_PP-OCRv4_server | X | √ | ppocr | 86 M | 简体中文、英文、数字 | √ |
452
464
  | ch_PP-OCRv3 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
453
465
  | ch_ppocr_mobile_v2.0 | X | √ | ppocr | 4.2 M | 简体中文、英文、数字 | √ |
466
+ | en_PP-OCRv4 | X | √ | ppocr | 8.6 M | **英文**、数字 | √ |
454
467
  | en_PP-OCRv3 | X | √ | ppocr | 8.5 M | **英文**、数字 | √ |
455
468
  | en_number_mobile_v2.0 | X | √ | ppocr | 1.8 M | **英文**、数字 | √ |
456
469
  | chinese_cht_PP-OCRv3 | X | √ | ppocr | 11 M | **繁体中文**、英文、数字 | X |
470
+ | japan_PP-OCRv3 | X | √ | ppocr | 9.6 M | **日文**、英文、数字 | √ |
471
+ | korean_PP-OCRv3 | X | √ | ppocr | 9.4 M | **韩文**、英文、数字 | √ |
472
+ | latin_PP-OCRv3 | X | √ | ppocr | 8.6 M | **拉丁文**、英文、数字 | √ |
473
+ | arabic_PP-OCRv3 | X | √ | ppocr | 8.6 M | **阿拉伯文**、英文、数字 | √ |
457
474
 
458
475
 
459
476
 
@@ -484,4 +501,3 @@ print(ocr_out)
484
501
  官方代码库:[https://github.com/breezedeus/cnocr](https://github.com/breezedeus/cnocr)。
485
502
 
486
503
 
487
-
@@ -39,6 +39,16 @@
39
39
  ---
40
40
  </div>
41
41
 
42
+ ### [Update 2024.11.28]:发布 V2.3.1
43
+
44
+ 主要变更:
45
+
46
+ * 基于 RapidOCR 集成 PPOCRv4 最新版 OCR 模型,提供更多的模型选择
47
+ * 新增支持 PP-OCRv4 识别模型,包括标准版和服务器版
48
+ * 修改读文件实现方式,支持 Windows 的中文路径
49
+ * 修复Bug:当使用多个进程时,transform_func 无法序列化
50
+ * 修复Bug:与 albumentations=1.4.* 兼容
51
+
42
52
  ### [Update 2023.12.24]:发布 V2.3
43
53
 
44
54
  主要变更:
@@ -376,13 +386,13 @@ print(ocr_out)
376
386
  | ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ------------------------------ | -------------------- |
377
387
  | db_shufflenet_v2 | √ | X | cnocr | 18 M | 简体中文、繁体中文、英文、数字 | √ |
378
388
  | **db_shufflenet_v2_small** | √ | X | cnocr | 12 M | 简体中文、繁体中文、英文、数字 | √ |
379
- | [db_shufflenet_v2_tiny](https://mp.weixin.qq.com/s/fHPNoGyo72EFApVhEgR6Nw) | √ | X | cnocr | 7.5 M | 简体中文、繁体中文、英文、数字 | √ |
380
389
  | db_mobilenet_v3 | √ | X | cnocr | 16 M | 简体中文、繁体中文、英文、数字 | √ |
381
390
  | db_mobilenet_v3_small | √ | X | cnocr | 7.9 M | 简体中文、繁体中文、英文、数字 | √ |
382
391
  | db_resnet34 | √ | X | cnocr | 86 M | 简体中文、繁体中文、英文、数字 | √ |
383
392
  | db_resnet18 | √ | X | cnocr | 47 M | 简体中文、繁体中文、英文、数字 | √ |
393
+ | ch_PP-OCRv4_det | X | √ | ppocr | 4.5 M | 简体中文、繁体中文、英文、数字 | √ |
394
+ | ch_PP-OCRv4_det_server | X | √ | ppocr | 108 M | 简体中文、繁体中文、英文、数字 | √ |
384
395
  | ch_PP-OCRv3_det | X | √ | ppocr | 2.3 M | 简体中文、繁体中文、英文、数字 | √ |
385
- | ch_PP-OCRv2_det | X | √ | ppocr | 2.2 M | 简体中文、繁体中文、英文、数字 | √ |
386
396
  | **en_PP-OCRv3_det** | X | √ | ppocr | 2.3 M | **英文**、数字 | √ |
387
397
 
388
398
 
@@ -419,11 +429,18 @@ print(ocr_out)
419
429
  | **number-densenet_lite_136-fc** 🆕 | √ | √ | cnocr | 2.7 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
420
430
  | **number-densenet_lite_136-gru** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 5.5 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
421
431
  | **number-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://gf.bilibili.com/item/detail/1104055055)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 55 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
432
+ | ch_PP-OCRv4 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
433
+ | ch_PP-OCRv4_server | X | √ | ppocr | 86 M | 简体中文、英文、数字 | √ |
422
434
  | ch_PP-OCRv3 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
423
435
  | ch_ppocr_mobile_v2.0 | X | √ | ppocr | 4.2 M | 简体中文、英文、数字 | √ |
436
+ | en_PP-OCRv4 | X | √ | ppocr | 8.6 M | **英文**、数字 | √ |
424
437
  | en_PP-OCRv3 | X | √ | ppocr | 8.5 M | **英文**、数字 | √ |
425
438
  | en_number_mobile_v2.0 | X | √ | ppocr | 1.8 M | **英文**、数字 | √ |
426
439
  | chinese_cht_PP-OCRv3 | X | √ | ppocr | 11 M | **繁体中文**、英文、数字 | X |
440
+ | japan_PP-OCRv3 | X | √ | ppocr | 9.6 M | **日文**、英文、数字 | √ |
441
+ | korean_PP-OCRv3 | X | √ | ppocr | 9.4 M | **韩文**、英文、数字 | √ |
442
+ | latin_PP-OCRv3 | X | √ | ppocr | 8.6 M | **拉丁文**、英文、数字 | √ |
443
+ | arabic_PP-OCRv3 | X | √ | ppocr | 8.6 M | **阿拉伯文**、英文、数字 | √ |
427
444
 
428
445
 
429
446
 
@@ -452,4 +469,3 @@ print(ocr_out)
452
469
  ---
453
470
 
454
471
  官方代码库:[https://github.com/breezedeus/cnocr](https://github.com/breezedeus/cnocr)。
455
-
@@ -17,4 +17,4 @@
17
17
  # specific language governing permissions and limitations
18
18
  # under the License.
19
19
 
20
- __version__ = '2.3.0.3'
20
+ __version__ = '2.3.1'
@@ -129,7 +129,7 @@ def main():
129
129
  det_models.append(('naive_det', 'onnx'))
130
130
  det_models.sort()
131
131
  det_model_name = st.sidebar.selectbox(
132
- '选择检测模型', det_models, index=det_models.index(('ch_PP-OCRv3_det', 'onnx'))
132
+ '选择检测模型', det_models, index=det_models.index(('ch_PP-OCRv4_det', 'onnx'))
133
133
  )
134
134
 
135
135
  all_models = list(REC_AVAILABLE_MODELS.all_models())
@@ -215,8 +215,8 @@ def visualize_example(example, fp_prefix):
215
215
  '-d',
216
216
  '--det-model-name',
217
217
  type=str,
218
- default='ch_PP-OCRv3_det',
219
- help='检测模型名称。默认值为 ch_PP-OCRv3_det',
218
+ default='ch_PP-OCRv4_det',
219
+ help='检测模型名称。默认值为 ch_PP-OCRv4_det',
220
220
  )
221
221
  @click.option(
222
222
  '--det-model-backend',
@@ -35,7 +35,7 @@ from .consts import AVAILABLE_MODELS as REC_AVAILABLE_MODELS
35
35
  from .utils import data_dir, read_img
36
36
  from .line_split import line_split
37
37
  from .recognizer import Recognizer
38
- from .ppocr import PPRecognizer, PP_SPACE
38
+ from .ppocr import PPRecognizer, RapidRecognizer, PP_SPACE
39
39
 
40
40
  logger = logging.getLogger(__name__)
41
41
 
@@ -64,7 +64,7 @@ class CnOcr(object):
64
64
  self,
65
65
  rec_model_name: str = 'densenet_lite_136-gru',
66
66
  *,
67
- det_model_name: str = 'ch_PP-OCRv3_det',
67
+ det_model_name: str = 'ch_PP-OCRv4_det',
68
68
  cand_alphabet: Optional[Union[Collection, str]] = None,
69
69
  context: str = 'cpu', # ['cpu', 'gpu', 'cuda']
70
70
  rec_model_fp: Optional[str] = None,
@@ -83,7 +83,7 @@ class CnOcr(object):
83
83
 
84
84
  Args:
85
85
  rec_model_name (str): 识别模型名称。默认为 `densenet_lite_136-gru`
86
- det_model_name (str): 检测模型名称。默认为 `ch_PP-OCRv3_det`
86
+ det_model_name (str): 检测模型名称。默认为 `ch_PP-OCRv4_det`
87
87
  cand_alphabet (Optional[Union[Collection, str]]): 待识别字符所在的候选集合。默认为 `None`,表示不限定识别字符范围
88
88
  context (str): 'cpu', or 'gpu'。表明预测时是使用CPU还是GPU。默认为 `cpu`。
89
89
  此参数仅在 `model_backend=='pytorch'` 时有效。
@@ -143,7 +143,8 @@ class CnOcr(object):
143
143
  if self.rec_space == REC_AVAILABLE_MODELS.CNOCR_SPACE:
144
144
  rec_cls = Recognizer
145
145
  elif self.rec_space == PP_SPACE:
146
- rec_cls = PPRecognizer
146
+ rec_name = REC_AVAILABLE_MODELS.get_value(rec_model_name, rec_model_backend, 'recognizer')
147
+ rec_cls = RapidRecognizer if rec_name == 'RapidRecognizer' else PPRecognizer
147
148
  if rec_vocab_fp is not None:
148
149
  logger.warning('param `vocab_fp` is invalid for %s models' % PP_SPACE)
149
150
  else:
@@ -335,6 +335,18 @@ class AvailableModels(object):
335
335
  )
336
336
  return CN_VOCAB_FP
337
337
 
338
+ def get_value(self, model_name, model_backend, key) -> Optional[Any]:
339
+ if (model_name, model_backend) in self.CNOCR_MODELS:
340
+ info = self.CNOCR_MODELS[(model_name, model_backend)]
341
+ elif (model_name, model_backend) in self.OUTER_MODELS:
342
+ info = self.OUTER_MODELS[(model_name, model_backend)]
343
+ else:
344
+ logger.warning(
345
+ 'no url is found for model %s' % ((model_name, model_backend),)
346
+ )
347
+ return None
348
+ return info.get(key)
349
+
338
350
  def get_epoch(self, model_name, model_backend) -> Optional[int]:
339
351
  if (model_name, model_backend) in self.CNOCR_MODELS:
340
352
  return self.CNOCR_MODELS[(model_name, model_backend)]['epoch']
@@ -138,14 +138,13 @@ class Bitmap(ImageOnlyTransform):
138
138
  return img
139
139
 
140
140
 
141
- class RandomStretchAug(alb.Resize):
141
+ class RandomStretchAug(ImageOnlyTransform):
142
142
  """保持高度不变的情况下,对图像的宽度进行随机拉伸"""
143
+
143
144
  def __init__(
144
- self, min_ratio=0.9, max_ratio=1.1, min_width=8, always_apply=False, p=1
145
- ):
146
- super(RandomStretchAug, self).__init__(
147
- height=0, width=0, always_apply=always_apply, p=p
148
- )
145
+ self, min_ratio=0.9, max_ratio=1.1, min_width=8, always_apply=False, p=1
146
+ ):
147
+ super().__init__(always_apply=always_apply, p=p)
149
148
  self.min_width = min_width
150
149
  self.min_ratio = min_ratio
151
150
  self.max_ratio = max_ratio
@@ -171,7 +170,7 @@ class CustomRandomCrop(ImageOnlyTransform):
171
170
  always_apply (bool): Whether to always apply the crop. Defaults to False.
172
171
  p (float): The probability of applying the crop. Defaults to 1.0.
173
172
  """
174
- super(CustomRandomCrop, self).__init__(always_apply, p)
173
+ super().__init__(always_apply=always_apply, p=p)
175
174
  self.crop_size = crop_size
176
175
 
177
176
  def cal_params(self, img):
@@ -210,7 +209,7 @@ class TransparentOverlay(ImageOnlyTransform):
210
209
  def __init__(
211
210
  self, max_height_ratio, max_width_ratio, alpha, always_apply=False, p=1.0
212
211
  ):
213
- super(TransparentOverlay, self).__init__(always_apply, p)
212
+ super().__init__(always_apply=always_apply, p=p)
214
213
  self.max_height_ratio = max_height_ratio
215
214
  self.max_width_ratio = max_width_ratio
216
215
  self.alpha = alpha
@@ -316,9 +315,9 @@ class TransformWrapper(object):
316
315
 
317
316
  _train_alb_transform = alb.Compose(
318
317
  [
319
- CustomRandomCrop((8, 10), p=0.8),
318
+ CustomRandomCrop(crop_size=(8, 10), always_apply=False, p=0.8),
320
319
  alb.OneOf([Erosion((2, 3)), Dilation((2, 3))], p=0.1),
321
- TransparentOverlay(1.0, 0.1, alpha=0.4, p=0.2), # 半透明的矩形框覆盖
320
+ TransparentOverlay(1.0, 0.1, alpha=0.4, always_apply=False, p=0.2), # 半透明的矩形框覆盖
322
321
  alb.Affine(shear={"x": (0, 3), "y": (-3, 0)}, cval=(255, 255, 255), p=0.03),
323
322
  alb.ShiftScaleRotate(
324
323
  shift_limit_x=(0, 0.04),
@@ -382,9 +381,9 @@ train_transform = TransformWrapper(_train_alb_transform)
382
381
 
383
382
  _ft_alb_transform = alb.Compose(
384
383
  [
385
- CustomRandomCrop((4, 4), p=0.8),
384
+ CustomRandomCrop(crop_size=(4, 4), always_apply=False, p=0.8),
386
385
  alb.OneOf([Erosion((2, 3)), Dilation((2, 3))], p=0.1),
387
- TransparentOverlay(1.0, 0.1, alpha=0.4, p=0.2), # 半透明的矩形框覆盖
386
+ TransparentOverlay(1.0, 0.1, alpha=0.4, always_apply=False, p=0.2), # 半透明的矩形框覆盖
388
387
  alb.RandomBrightnessContrast(0.1, 0.1, True, p=0.1),
389
388
  alb.ImageCompression(95, p=0.3),
390
389
  alb.GaussNoise(20, p=0.2),
@@ -413,7 +412,7 @@ ft_transform = TransformWrapper(_ft_alb_transform)
413
412
 
414
413
  _test_alb_transform = alb.Compose(
415
414
  [
416
- CustomRandomCrop((6, 8), p=0.8),
415
+ CustomRandomCrop(crop_size=(6, 8), p=0.8),
417
416
  ToSingleChannelGray(always_apply=True),
418
417
  CustomNormalize(always_apply=True),
419
418
  # alb.Normalize(0.456045, 0.224567, always_apply=True),
@@ -22,6 +22,8 @@
22
22
  from datasets import Dataset, Image
23
23
  import numpy as np
24
24
  import torch
25
+ import os
26
+ from pathlib import Path
25
27
 
26
28
  from .consts import IMG_STANDARD_HEIGHT
27
29
  from .utils import read_tsv_file, pad_img_seq
@@ -41,6 +43,25 @@ def preprocess(img):
41
43
  return img.resize(target_w_h)
42
44
 
43
45
 
46
+ def apply_transforms(img, transforms):
47
+ """Apply transforms to a single image."""
48
+ img = np.array(img)
49
+ if img.ndim == 2:
50
+ img = np.expand_dims(img, 0)
51
+ return transforms(torch.from_numpy(img))
52
+
53
+
54
+ def create_transform_func(transforms):
55
+ """Create a transform function that can be pickled."""
56
+ def transform_func(examples):
57
+ outs = []
58
+ for img in examples['image']:
59
+ outs.append(apply_transforms(img, transforms))
60
+ examples['transformed_image'] = outs
61
+ return examples
62
+ return transform_func
63
+
64
+
44
65
  def gen_dataset(
45
66
  index_fp, img_folder=None, transforms=None, mode='train', num_workers=None
46
67
  ) -> Dataset:
@@ -80,18 +101,7 @@ def gen_dataset(
80
101
  dataset = dataset.map(map_func, batched=True, num_proc=num_workers)
81
102
 
82
103
  if transforms is not None:
83
-
84
- def transform_func(examples):
85
- outs = []
86
- for img in examples['image']:
87
- img = np.array(img)
88
- if img.ndim == 2:
89
- img = np.expand_dims(img, 0)
90
- outs.append(transforms(torch.from_numpy(img)))
91
- examples['transformed_image'] = outs
92
- return examples
93
-
94
- dataset.set_transform(transform_func)
104
+ dataset.set_transform(create_transform_func(transforms))
95
105
  return dataset
96
106
 
97
107
 
@@ -172,7 +172,7 @@ def main():
172
172
  with gr.Column(min_width=200, variant='panel', scale=1):
173
173
  gr.Markdown('### 模型设置')
174
174
  det_model_name = gr.Dropdown(
175
- label='选择检测模型', choices=det_models, value='ch_PP-OCRv3_det::onnx',
175
+ label='选择检测模型', choices=det_models, value='ch_PP-OCRv4_det::onnx',
176
176
  )
177
177
 
178
178
  rec_model_name = gr.Dropdown(
@@ -3,5 +3,6 @@
3
3
  from ..consts import AVAILABLE_MODELS
4
4
  from .consts import MODEL_LABELS_FILE_DICT, PP_SPACE
5
5
  from .pp_recognizer import PPRecognizer
6
+ from .rapid_recognizer import RapidRecognizer
6
7
 
7
8
  AVAILABLE_MODELS.register_models(MODEL_LABELS_FILE_DICT, space=PP_SPACE)
@@ -0,0 +1,78 @@
1
+ # coding: utf-8
2
+ # Copyright (C) 2022, [Breezedeus](https://github.com/breezedeus).
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ from pathlib import Path
21
+
22
+
23
+ VOCAB_DIR = Path(__file__).parent / "utils"
24
+
25
+ MODEL_LABELS_FILE_DICT = {
26
+ ("ch_PP-OCRv3", "onnx"): {
27
+ "vocab_fp": VOCAB_DIR / "ppocr_keys_v1.txt", # 简体中英文
28
+ "url": "ch_PP-OCRv3_rec_infer-onnx.zip",
29
+ },
30
+ ("ch_ppocr_mobile_v2.0", "onnx"): {
31
+ "vocab_fp": VOCAB_DIR / "ppocr_keys_v1.txt",
32
+ "url": "ch_ppocr_mobile_v2.0_rec_infer-onnx.zip",
33
+ },
34
+ ("en_number_mobile_v2.0", "onnx"): {
35
+ "vocab_fp": VOCAB_DIR / "en_dict.txt",
36
+ "url": "en_number_mobile_v2.0_rec_infer-onnx.zip",
37
+ },
38
+ ("chinese_cht_PP-OCRv3", "onnx"): {
39
+ "vocab_fp": VOCAB_DIR / "chinese_cht_dict.txt", # 繁体中文
40
+ "url": "chinese_cht_PP-OCRv3_rec_infer-onnx.zip",
41
+ },
42
+ ("japan_PP-OCRv3", "onnx"): {
43
+ "recognizer": "RapidRecognizer",
44
+ "repo": "breezedeus/cnocr-ppocr-japan_PP-OCRv3",
45
+ },
46
+ ("korean_PP-OCRv3", "onnx"): {
47
+ "recognizer": "RapidRecognizer",
48
+ "repo": "breezedeus/cnocr-ppocr-korean_PP-OCRv3",
49
+ },
50
+ ("latin_PP-OCRv3", "onnx"): {
51
+ "recognizer": "RapidRecognizer",
52
+ "repo": "breezedeus/cnocr-ppocr-latin_PP-OCRv3",
53
+ },
54
+ ("arabic_PP-OCRv3", "onnx"): {
55
+ "recognizer": "RapidRecognizer",
56
+ "repo": "breezedeus/cnocr-ppocr-arabic_PP-OCRv3",
57
+ },
58
+ ("en_PP-OCRv3", "onnx"): {
59
+ "vocab_fp": VOCAB_DIR / "en_dict.txt", # 英文
60
+ "url": "en_PP-OCRv3_rec_infer-onnx.zip",
61
+ "recognizer": "RapidRecognizer",
62
+ "repo": "breezedeus/cnocr-ppocr-en_PP-OCRv3",
63
+ },
64
+ ("en_PP-OCRv4", "onnx"): {
65
+ "recognizer": "RapidRecognizer",
66
+ "repo": "breezedeus/cnocr-ppocr-en_PP-OCRv4",
67
+ },
68
+ ("ch_PP-OCRv4", "onnx"): {
69
+ "recognizer": "RapidRecognizer",
70
+ "repo": "breezedeus/cnocr-ppocr-ch_PP-OCRv4",
71
+ },
72
+ ("ch_PP-OCRv4_server", "onnx"): {
73
+ "recognizer": "RapidRecognizer",
74
+ "repo": "breezedeus/cnocr-ppocr-ch_PP-OCRv4_server",
75
+ },
76
+ }
77
+
78
+ PP_SPACE = "ppocr"
@@ -0,0 +1,135 @@
1
+ # coding: utf-8
2
+ # Copyright (C) 2022-2024, [Breezedeus](https://github.com/breezedeus).
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements.
5
+
6
+ import os
7
+ import logging
8
+ from typing import Union, Optional, List, Tuple
9
+ from pathlib import Path
10
+
11
+ import numpy as np
12
+ from rapidocr_onnxruntime.ch_ppocr_rec.text_recognize import TextRecognizer
13
+ from cnstd.utils import prepare_model_files
14
+
15
+ from ..utils import data_dir, read_img
16
+ from ..recognizer import Recognizer
17
+ from .consts import PP_SPACE
18
+ from ..consts import MODEL_VERSION, AVAILABLE_MODELS
19
+
20
+
21
+ logger = logging.getLogger(__name__)
22
+
23
+
24
+ class RapidRecognizer(Recognizer):
25
+ def __init__(
26
+ self,
27
+ model_name: str = "ch_PP-OCRv3",
28
+ *,
29
+ model_fp: Optional[str] = None,
30
+ root: Union[str, Path] = data_dir(),
31
+ context: str = "cpu", # ['cpu', 'gpu']
32
+ rec_image_shape: str = "3, 48, 320",
33
+ **kwargs
34
+ ):
35
+ """
36
+ 基于 rapidocr_onnxruntime 的文本识别器。
37
+
38
+ Args:
39
+ model_name (str): 模型名称。默认为 `ch_PP-OCRv3`
40
+ model_fp (Optional[str]): 如果不使用系统自带的模型,可以通过此参数直接指定所使用的模型文件('.onnx' 文件)
41
+ root (Union[str, Path]): 模型文件所在的根目录
42
+ context (str): 使用的设备。默认为 `cpu`,可选 `gpu`
43
+ rec_image_shape (str): 输入图片尺寸,无需更改使用默认值即可。默认值:`"3, 32, 320"`
44
+ **kwargs: 其他参数
45
+ """
46
+ self.rec_image_shape = [int(v) for v in rec_image_shape.split(",")]
47
+ self._model_name = model_name
48
+ self._model_backend = "onnx"
49
+ use_gpu = context.lower() not in ("cpu", "mps")
50
+
51
+ self._assert_and_prepare_model_files(model_fp, root)
52
+
53
+ config = {
54
+ "use_cuda": use_gpu,
55
+ "rec_img_shape": self.rec_image_shape,
56
+ "rec_batch_num": 6,
57
+ "model_path": self._model_fp,
58
+ }
59
+ self.recognizer = TextRecognizer(config)
60
+
61
+ def _assert_and_prepare_model_files(self, model_fp, root):
62
+ if model_fp is not None and not os.path.isfile(model_fp):
63
+ raise FileNotFoundError("can not find model file %s" % model_fp)
64
+
65
+ if model_fp is not None:
66
+ self._model_fp = model_fp
67
+ return
68
+
69
+ root = os.path.join(root, MODEL_VERSION)
70
+ self._model_dir = os.path.join(root, PP_SPACE, self._model_name)
71
+ model_fp = os.path.join(self._model_dir, "%s_rec_infer.onnx" % self._model_name)
72
+ if not os.path.isfile(model_fp):
73
+ logger.warning("can not find model file %s" % model_fp)
74
+ if (self._model_name, self._model_backend) not in AVAILABLE_MODELS:
75
+ raise NotImplementedError(
76
+ "%s is not a downloadable model"
77
+ % ((self._model_name, self._model_backend),)
78
+ )
79
+ remote_repo = AVAILABLE_MODELS.get_value(
80
+ self._model_name, self._model_backend, "repo"
81
+ )
82
+ model_fp = prepare_model_files(model_fp, remote_repo)
83
+
84
+ self._model_fp = model_fp
85
+ logger.info("use model: %s" % self._model_fp)
86
+
87
+ def recognize(
88
+ self, img_list: List[Union[str, Path, np.ndarray]], batch_size: int = 6
89
+ ) -> List[Tuple[str, float]]:
90
+ """
91
+ 识别图片中的文字。
92
+ Args:
93
+ img_list: 支持以下格式的图片数据:
94
+ + 图片路径
95
+ + 已经从图片文件中读入的数据
96
+ batch_size: 待处理图片数据的批大小。
97
+
98
+ Returns:
99
+ 列表,每个元素是对应图片的识别结果,由 (text, score) 组成,其中:
100
+ + text: 识别出的文本
101
+ + score: 识别结果的得分
102
+ """
103
+ if not isinstance(img_list, (list, tuple)):
104
+ img_list = [img_list]
105
+
106
+ self.recognizer.rec_batch_num = batch_size
107
+
108
+ img_data_list = []
109
+ for img in img_list:
110
+ if isinstance(img, (str, Path)):
111
+ img = read_img(img, gray=False)
112
+ if len(img.shape) == 3 and img.shape[2] == 3:
113
+ img = img[..., ::-1] # RGB to BGR
114
+ img_data_list.append(img)
115
+
116
+ results, _ = self.recognizer(img_data_list)
117
+ return results
118
+
119
+ def recognize_one_line(
120
+ self, img: Union[str, Path, np.ndarray]
121
+ ) -> Tuple[str, float]:
122
+ """
123
+ 识别图片中的一行文字。
124
+ Args:
125
+ img: 支持以下格式的图片数据:
126
+ + 图片路径
127
+ + 已经从图片文件中读入的数据
128
+
129
+ Returns:
130
+ (text, score):
131
+ + text: 识别出的文本
132
+ + score: 识别结果的得分
133
+ """
134
+ results = self.recognize([img])
135
+ return results[0]
@@ -23,12 +23,11 @@ import os
23
23
  from pathlib import Path
24
24
  import logging
25
25
  import platform
26
- import zipfile
27
26
  import requests
28
27
  from typing import Union, Any, Tuple, List, Optional, Dict
29
28
 
30
29
  from tqdm import tqdm
31
- from PIL import Image
30
+ from PIL import Image, ImageOps
32
31
  import cv2
33
32
  import numpy as np
34
33
  import torch
@@ -272,16 +271,18 @@ def read_img(path: Union[str, Path], gray=True) -> np.ndarray:
272
271
  * when `gray==True`, return a gray image, with dim [height, width, 1], with values range from 0 to 255
273
272
  * when `gray==False`, return a color image, with dim [height, width, 3], with values range from 0 to 255
274
273
  """
274
+ try:
275
+ img = Image.open(path)
276
+ img = ImageOps.exif_transpose(img) # 识别旋转后的图片(pillow不会自动识别)
277
+ except Exception as e:
278
+ raise FileNotFoundError(f'Error loading image: {path}')
279
+
275
280
  if gray:
276
- img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
277
- if img is None:
278
- raise FileNotFoundError(f'Error loading image: {path}')
279
- return np.expand_dims(img, -1)
281
+ img = img.convert('L')
282
+ return np.expand_dims(np.array(img), -1)
280
283
  else:
281
- img = cv2.imread(path)
282
- if img is None:
283
- raise FileNotFoundError(f'Error loading image: {path}')
284
- return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
284
+ img = img.convert('RGB')
285
+ return np.array(img)
285
286
 
286
287
 
287
288
  def save_img(img: Union[Tensor, np.ndarray], path):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cnocr
3
- Version: 2.3.0.3
3
+ Version: 2.3.1
4
4
  Summary: Python3 package for Chinese/English OCR, with small pretrained models
5
5
  Home-page: https://github.com/breezedeus/cnocr
6
6
  Author: breezedeus
@@ -69,6 +69,16 @@ License-File: LICENSE
69
69
  ---
70
70
  </div>
71
71
 
72
+ ### [Update 2024.11.28]:发布 V2.3.1
73
+
74
+ 主要变更:
75
+
76
+ * 基于 RapidOCR 集成 PPOCRv4 最新版 OCR 模型,提供更多的模型选择
77
+ * 新增支持 PP-OCRv4 识别模型,包括标准版和服务器版
78
+ * 修改读文件实现方式,支持 Windows 的中文路径
79
+ * 修复Bug:当使用多个进程时,transform_func 无法序列化
80
+ * 修复Bug:与 albumentations=1.4.* 兼容
81
+
72
82
  ### [Update 2023.12.24]:发布 V2.3
73
83
 
74
84
  主要变更:
@@ -406,13 +416,13 @@ print(ocr_out)
406
416
  | ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ------------------------------ | -------------------- |
407
417
  | db_shufflenet_v2 | √ | X | cnocr | 18 M | 简体中文、繁体中文、英文、数字 | √ |
408
418
  | **db_shufflenet_v2_small** | √ | X | cnocr | 12 M | 简体中文、繁体中文、英文、数字 | √ |
409
- | [db_shufflenet_v2_tiny](https://mp.weixin.qq.com/s/fHPNoGyo72EFApVhEgR6Nw) | √ | X | cnocr | 7.5 M | 简体中文、繁体中文、英文、数字 | √ |
410
419
  | db_mobilenet_v3 | √ | X | cnocr | 16 M | 简体中文、繁体中文、英文、数字 | √ |
411
420
  | db_mobilenet_v3_small | √ | X | cnocr | 7.9 M | 简体中文、繁体中文、英文、数字 | √ |
412
421
  | db_resnet34 | √ | X | cnocr | 86 M | 简体中文、繁体中文、英文、数字 | √ |
413
422
  | db_resnet18 | √ | X | cnocr | 47 M | 简体中文、繁体中文、英文、数字 | √ |
423
+ | ch_PP-OCRv4_det | X | √ | ppocr | 4.5 M | 简体中文、繁体中文、英文、数字 | √ |
424
+ | ch_PP-OCRv4_det_server | X | √ | ppocr | 108 M | 简体中文、繁体中文、英文、数字 | √ |
414
425
  | ch_PP-OCRv3_det | X | √ | ppocr | 2.3 M | 简体中文、繁体中文、英文、数字 | √ |
415
- | ch_PP-OCRv2_det | X | √ | ppocr | 2.2 M | 简体中文、繁体中文、英文、数字 | √ |
416
426
  | **en_PP-OCRv3_det** | X | √ | ppocr | 2.3 M | **英文**、数字 | √ |
417
427
 
418
428
 
@@ -449,11 +459,18 @@ print(ocr_out)
449
459
  | **number-densenet_lite_136-fc** 🆕 | √ | √ | cnocr | 2.7 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
450
460
  | **number-densenet_lite_136-gru** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 5.5 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
451
461
  | **number-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://gf.bilibili.com/item/detail/1104055055)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 55 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
462
+ | ch_PP-OCRv4 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
463
+ | ch_PP-OCRv4_server | X | √ | ppocr | 86 M | 简体中文、英文、数字 | √ |
452
464
  | ch_PP-OCRv3 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
453
465
  | ch_ppocr_mobile_v2.0 | X | √ | ppocr | 4.2 M | 简体中文、英文、数字 | √ |
466
+ | en_PP-OCRv4 | X | √ | ppocr | 8.6 M | **英文**、数字 | √ |
454
467
  | en_PP-OCRv3 | X | √ | ppocr | 8.5 M | **英文**、数字 | √ |
455
468
  | en_number_mobile_v2.0 | X | √ | ppocr | 1.8 M | **英文**、数字 | √ |
456
469
  | chinese_cht_PP-OCRv3 | X | √ | ppocr | 11 M | **繁体中文**、英文、数字 | X |
470
+ | japan_PP-OCRv3 | X | √ | ppocr | 9.6 M | **日文**、英文、数字 | √ |
471
+ | korean_PP-OCRv3 | X | √ | ppocr | 9.4 M | **韩文**、英文、数字 | √ |
472
+ | latin_PP-OCRv3 | X | √ | ppocr | 8.6 M | **拉丁文**、英文、数字 | √ |
473
+ | arabic_PP-OCRv3 | X | √ | ppocr | 8.6 M | **阿拉伯文**、英文、数字 | √ |
457
474
 
458
475
 
459
476
 
@@ -484,4 +501,3 @@ print(ocr_out)
484
501
  官方代码库:[https://github.com/breezedeus/cnocr](https://github.com/breezedeus/cnocr)。
485
502
 
486
503
 
487
-
@@ -43,6 +43,7 @@ cnocr/models/ocr_model.py
43
43
  cnocr/ppocr/__init__.py
44
44
  cnocr/ppocr/consts.py
45
45
  cnocr/ppocr/pp_recognizer.py
46
+ cnocr/ppocr/rapid_recognizer.py
46
47
  cnocr/ppocr/utility.py
47
48
  cnocr/ppocr/postprocess/__init__.py
48
49
  cnocr/ppocr/postprocess/rec_postprocess.py
@@ -8,7 +8,8 @@ wandb
8
8
  torchmetrics
9
9
  pillow>=5.3.0
10
10
  onnx
11
- cnstd>=1.2.3.4
11
+ cnstd>=1.2.5.1
12
+ rapidocr_onnxruntime<1.4
12
13
 
13
14
  [dev]
14
15
  albumentations
@@ -47,7 +47,8 @@ required = [
47
47
  "torchmetrics",
48
48
  "pillow>=5.3.0",
49
49
  "onnx",
50
- "cnstd>=1.2.3.4",
50
+ "cnstd>=1.2.5.1",
51
+ "rapidocr_onnxruntime<1.4",
51
52
  ]
52
53
  extras_require = {
53
54
  "ort-cpu": ["onnxruntime"],
@@ -1,48 +0,0 @@
1
- # coding: utf-8
2
- # Copyright (C) 2022, [Breezedeus](https://github.com/breezedeus).
3
- # Licensed to the Apache Software Foundation (ASF) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The ASF licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
-
20
- from pathlib import Path
21
-
22
-
23
- VOCAB_DIR = Path(__file__).parent / 'utils'
24
-
25
- MODEL_LABELS_FILE_DICT = {
26
- ('ch_PP-OCRv3', 'onnx'): {
27
- 'vocab_fp': VOCAB_DIR / 'ppocr_keys_v1.txt', # 简体中英文
28
- 'url': 'ch_PP-OCRv3_rec_infer-onnx.zip',
29
- },
30
- ('ch_ppocr_mobile_v2.0', 'onnx'): {
31
- 'vocab_fp': VOCAB_DIR / 'ppocr_keys_v1.txt',
32
- 'url': 'ch_ppocr_mobile_v2.0_rec_infer-onnx.zip',
33
- },
34
- ('en_PP-OCRv3', 'onnx'): {
35
- 'vocab_fp': VOCAB_DIR / 'en_dict.txt', # 英文
36
- 'url': 'en_PP-OCRv3_rec_infer-onnx.zip',
37
- },
38
- ('en_number_mobile_v2.0', 'onnx'): {
39
- 'vocab_fp': VOCAB_DIR / 'en_dict.txt',
40
- 'url': 'en_number_mobile_v2.0_rec_infer-onnx.zip',
41
- },
42
- ('chinese_cht_PP-OCRv3', 'onnx'): {
43
- 'vocab_fp': VOCAB_DIR / 'chinese_cht_dict.txt', # 繁体中文
44
- 'url': 'chinese_cht_PP-OCRv3_rec_infer-onnx.zip',
45
- },
46
- }
47
-
48
- PP_SPACE = 'ppocr'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -73,6 +73,7 @@ class PPRecognizer(Recognizer):
73
73
 
74
74
  vocab_fp = AVAILABLE_MODELS.get_vocab_fp(self._model_name, self._model_backend)
75
75
  self._assert_and_prepare_model_files(model_fp, root)
76
+ logger.info('use model: %s' % self._model_fp)
76
77
  postprocess_params = {
77
78
  'name': 'CTCLabelDecode',
78
79
  'character_dict_path': vocab_fp,
@@ -114,7 +115,6 @@ class PPRecognizer(Recognizer):
114
115
  ) # download the .zip file and unzip
115
116
 
116
117
  self._model_fp = model_fp
117
- logger.info('use model: %s' % self._model_fp)
118
118
 
119
119
  def resize_norm_img(self, img, max_wh_ratio):
120
120
  """
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes