cnocr 2.3.0.2__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.2 → cnocr-2.3.1}/PKG-INFO +32 -16
  2. {cnocr-2.3.0.2 → cnocr-2.3.1}/README.md +31 -15
  3. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/__version__.py +1 -1
  4. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/app.py +2 -2
  5. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/cli.py +2 -2
  6. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/cn_ocr.py +5 -4
  7. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/consts.py +12 -0
  8. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/data_utils/transforms.py +12 -13
  9. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/dataset_utils.py +22 -12
  10. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/gradio_app.py +1 -1
  11. {cnocr-2.3.0.2 → 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.2 → cnocr-2.3.1}/cnocr/utils.py +11 -10
  15. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr.egg-info/PKG-INFO +32 -16
  16. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr.egg-info/SOURCES.txt +1 -0
  17. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr.egg-info/requires.txt +2 -1
  18. {cnocr-2.3.0.2 → cnocr-2.3.1}/setup.py +2 -1
  19. cnocr-2.3.0.2/cnocr/ppocr/consts.py +0 -48
  20. {cnocr-2.3.0.2 → cnocr-2.3.1}/LICENSE +0 -0
  21. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/__init__.py +0 -0
  22. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/classification/__init__.py +0 -0
  23. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/classification/dataset.py +0 -0
  24. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/classification/image_classifier.py +0 -0
  25. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/clf_cli.py +0 -0
  26. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/data_utils/__init__.py +0 -0
  27. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/data_utils/aug.py +0 -0
  28. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/data_utils/block_shuffle.py +0 -0
  29. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/data_utils/utils.py +0 -0
  30. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/dataset.py +0 -0
  31. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/gradio_app2.py +0 -0
  32. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/label_cn.txt +0 -0
  33. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/label_number.txt +0 -0
  34. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/line_split.py +0 -0
  35. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/lr_scheduler.py +0 -0
  36. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/models/__init__.py +0 -0
  37. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/models/ctc.py +0 -0
  38. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/models/densenet.py +0 -0
  39. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/models/mobilenet.py +0 -0
  40. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/models/ocr_model.py +0 -0
  41. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/ppocr/postprocess/__init__.py +0 -0
  42. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/ppocr/postprocess/rec_postprocess.py +0 -0
  43. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/ppocr/pp_recognizer.py +1 -1
  44. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/ppocr/utility.py +0 -0
  45. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/ppocr/utils/__init__.py +0 -0
  46. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/ppocr/utils/chinese_cht_dict.txt +0 -0
  47. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/ppocr/utils/en_dict.txt +0 -0
  48. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/ppocr/utils/ppocr_keys_v1.txt +0 -0
  49. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/recognizer.py +0 -0
  50. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/serve.py +0 -0
  51. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr/trainer.py +0 -0
  52. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr.egg-info/dependency_links.txt +0 -0
  53. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr.egg-info/entry_points.txt +0 -0
  54. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr.egg-info/not-zip-safe +0 -0
  55. {cnocr-2.3.0.2 → cnocr-2.3.1}/cnocr.egg-info/top_level.txt +0 -0
  56. {cnocr-2.3.0.2 → cnocr-2.3.1}/setup.cfg +0 -0
  57. {cnocr-2.3.0.2 → cnocr-2.3.1}/tests/test_cnocr.py +0 -0
  58. {cnocr-2.3.0.2 → cnocr-2.3.1}/tests/test_dataset.py +0 -0
  59. {cnocr-2.3.0.2 → cnocr-2.3.1}/tests/test_models.py +0 -0
  60. {cnocr-2.3.0.2 → cnocr-2.3.1}/tests/test_ppocr.py +0 -0
  61. {cnocr-2.3.0.2 → cnocr-2.3.1}/tests/test_pytorch.py +0 -0
  62. {cnocr-2.3.0.2 → cnocr-2.3.1}/tests/test_trainer.py +0 -0
  63. {cnocr-2.3.0.2 → 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.2
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
@@ -36,7 +36,7 @@ License-File: LICENSE
36
36
  [![Downloads](https://static.pepy.tech/personalized-badge/cnocr?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads)](https://pepy.tech/project/cnocr)
37
37
  [![Visitors](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2Fbreezedeus%2FCnOCR&label=Visitors&countColor=%23f5c791&style=flat&labelStyle=none)](https://visitorbadge.io/status?path=https%3A%2F%2Fgithub.com%2Fbreezedeus%2FCnOCR)
38
38
  [![license](https://img.shields.io/github/license/breezedeus/cnocr)](./LICENSE)
39
- [![Docs](https://readthedocs.org/projects/cnocr/badge/?version=latest)](https://cnocr.readthedocs.io/zh/latest/?badge=latest)
39
+ [![Docs](https://readthedocs.org/projects/cnocr/badge/?version=latest)](https://cnocr.readthedocs.io/zh-cn/stable/?badge=latest)
40
40
  [![PyPI version](https://badge.fury.io/py/cnocr.svg)](https://badge.fury.io/py/cnocr)
41
41
  [![forks](https://img.shields.io/github/forks/breezedeus/cnocr)](https://github.com/breezedeus/cnocr)
42
42
  [![stars](https://img.shields.io/github/stars/breezedeus/cnocr)](https://github.com/breezedeus/cnocr)
@@ -44,12 +44,12 @@ License-File: LICENSE
44
44
  ![last-commit](https://img.shields.io/github/last-commit/breezedeus/cnocr)
45
45
  [![Twitter](https://img.shields.io/twitter/url?url=https%3A%2F%2Ftwitter.com%2Fbreezedeus)](https://twitter.com/breezedeus)
46
46
 
47
- [📖 文档](https://cnocr.readthedocs.io/zh/latest/) |
48
- [🛠️ 安装](https://cnocr.readthedocs.io/zh/latest/install/) |
49
- [🧳 可用模型](https://cnocr.readthedocs.io/zh/latest/models/) |
50
- [🕹 模型训练](https://cnocr.readthedocs.io/zh/latest/train/) |
47
+ [📖 文档](https://cnocr.readthedocs.io/zh-cn/stable/) |
48
+ [🛠️ 安装](https://cnocr.readthedocs.io/zh-cn/stable/install/) |
49
+ [🧳 可用模型](https://cnocr.readthedocs.io/zh-cn/stable/models/) |
50
+ [🕹 模型训练](https://cnocr.readthedocs.io/zh-cn/stable/train/) |
51
51
  [🛀🏻 在线Demo](https://huggingface.co/spaces/breezedeus/CnOCR-Demo) |
52
- [💬 交流群](https://cnocr.readthedocs.io/zh/latest/contact/)
52
+ [💬 交流群](https://www.breezedeus.com/article/join-group)
53
53
 
54
54
  </div>
55
55
 
@@ -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
  主要变更:
@@ -88,7 +98,7 @@ License-File: LICENSE
88
98
 
89
99
 
90
100
 
91
- [**CnOCR**](https://github.com/breezedeus/cnocr) 是 **Python 3** 下的**文字识别**(**Optical Character Recognition**,简称**OCR**)工具包,支持**简体中文**、**繁体中文**(部分模型)、**英文**和**数字**的常见字符识别,支持竖排文字的识别。自带了**20+个** [训练好的模型](https://cnocr.readthedocs.io/zh/latest/models/),适用于不同应用场景,安装后即可直接使用。同时,CnOCR也提供简单的[训练命令](https://cnocr.readthedocs.io/zh/latest/train/)供使用者训练自己的模型。欢迎扫码加小助手为好友,备注 `ocr`,小助手会定期统一邀请大家入群:
101
+ [**CnOCR**](https://github.com/breezedeus/cnocr) 是 **Python 3** 下的**文字识别**(**Optical Character Recognition**,简称**OCR**)工具包,支持**简体中文**、**繁体中文**(部分模型)、**英文**和**数字**的常见字符识别,支持竖排文字的识别。自带了**20+个** [训练好的模型](https://cnocr.readthedocs.io/zh-cn/stable/models/),适用于不同应用场景,安装后即可直接使用。同时,CnOCR也提供简单的[训练命令](https://cnocr.readthedocs.io/zh-cn/stable/train/)供使用者训练自己的模型。欢迎扫码加小助手为好友,备注 `ocr`,小助手会定期统一邀请大家入群:
92
102
 
93
103
  <div align="center">
94
104
  <img src="https://huggingface.co/datasets/breezedeus/cnocr-wx-qr-code/resolve/main/wx-qr-code.JPG" alt="微信群二维码" width="300px"/>
@@ -315,7 +325,7 @@ $ pip install cnocr[ort-cpu] -i https://mirrors.aliyun.com/pypi/simple
315
325
  >
316
326
  > 请使用 **Python3**(3.7.\*~3.10.\*之间的版本应该都行),没测过Python2下是否ok。
317
327
 
318
- 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh/latest/install/)。
328
+ 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh-cn/stable/install/)。
319
329
 
320
330
  > **Warning**
321
331
  >
@@ -331,7 +341,7 @@ $ pip install cnocr[ort-cpu] -i https://mirrors.aliyun.com/pypi/simple
331
341
  $ docker pull breezedeus/cnocr:latest
332
342
  ```
333
343
 
334
- 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh/latest/install/)。
344
+ 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh-cn/stable/install/)。
335
345
 
336
346
 
337
347
 
@@ -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
 
@@ -421,7 +431,7 @@ print(ocr_out)
421
431
 
422
432
  相比于 CnOCR V2.2.* 版本,**V2.3** 中的大部分模型都经过了重新训练和精调,精度比旧版模型更高。同时,加入了两个参数量更多的模型系列:
423
433
 
424
- * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,2024 年 2 月都会免费开源。
434
+ * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,后续会免费开源。
425
435
  * `*-densenet_lite_666-gru_large`:**Pro 模型**,购买后可使用。购买链接见文档:
426
436
 
427
437
  **V2.3** 中的模型按使用场景可以分为以下几大类:
@@ -433,7 +443,7 @@ print(ocr_out)
433
443
 
434
444
  > 注意 ⚠️:以上说明仅供参考,具体选择模型时建议以实际效果为准。
435
445
 
436
- 更多说明见:[可用模型](https://cnocr.readthedocs.io/zh/latest/models/)。
446
+ 更多说明见:[可用模型](https://cnocr.readthedocs.io/zh-cn/stable/models/)。
437
447
 
438
448
  | `rec_model_name` | PyTorch 版本 | ONNX 版本 | 模型原始来源 | 模型文件大小 | 支持语言 | 是否支持竖排文字识别 |
439
449
  | ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ----------------------------------- | -------------------- |
@@ -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
 
@@ -477,11 +494,10 @@ print(ocr_out)
477
494
 
478
495
  ## 给作者来杯咖啡
479
496
 
480
- 开源不易,如果此项目对您有帮助,可以考虑 [给作者加点油🥤,鼓鼓气💪🏻](https://cnocr.readthedocs.io/zh/latest/buymeacoffee/) 。
497
+ 开源不易,如果此项目对您有帮助,可以考虑 [给作者加点油🥤,鼓鼓气💪🏻](https://cnocr.readthedocs.io/zh-cn/stable/buymeacoffee/) 。
481
498
 
482
499
  ---
483
500
 
484
501
  官方代码库:[https://github.com/breezedeus/cnocr](https://github.com/breezedeus/cnocr)。
485
502
 
486
503
 
487
-
@@ -6,7 +6,7 @@
6
6
  [![Downloads](https://static.pepy.tech/personalized-badge/cnocr?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads)](https://pepy.tech/project/cnocr)
7
7
  [![Visitors](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2Fbreezedeus%2FCnOCR&label=Visitors&countColor=%23f5c791&style=flat&labelStyle=none)](https://visitorbadge.io/status?path=https%3A%2F%2Fgithub.com%2Fbreezedeus%2FCnOCR)
8
8
  [![license](https://img.shields.io/github/license/breezedeus/cnocr)](./LICENSE)
9
- [![Docs](https://readthedocs.org/projects/cnocr/badge/?version=latest)](https://cnocr.readthedocs.io/zh/latest/?badge=latest)
9
+ [![Docs](https://readthedocs.org/projects/cnocr/badge/?version=latest)](https://cnocr.readthedocs.io/zh-cn/stable/?badge=latest)
10
10
  [![PyPI version](https://badge.fury.io/py/cnocr.svg)](https://badge.fury.io/py/cnocr)
11
11
  [![forks](https://img.shields.io/github/forks/breezedeus/cnocr)](https://github.com/breezedeus/cnocr)
12
12
  [![stars](https://img.shields.io/github/stars/breezedeus/cnocr)](https://github.com/breezedeus/cnocr)
@@ -14,12 +14,12 @@
14
14
  ![last-commit](https://img.shields.io/github/last-commit/breezedeus/cnocr)
15
15
  [![Twitter](https://img.shields.io/twitter/url?url=https%3A%2F%2Ftwitter.com%2Fbreezedeus)](https://twitter.com/breezedeus)
16
16
 
17
- [📖 文档](https://cnocr.readthedocs.io/zh/latest/) |
18
- [🛠️ 安装](https://cnocr.readthedocs.io/zh/latest/install/) |
19
- [🧳 可用模型](https://cnocr.readthedocs.io/zh/latest/models/) |
20
- [🕹 模型训练](https://cnocr.readthedocs.io/zh/latest/train/) |
17
+ [📖 文档](https://cnocr.readthedocs.io/zh-cn/stable/) |
18
+ [🛠️ 安装](https://cnocr.readthedocs.io/zh-cn/stable/install/) |
19
+ [🧳 可用模型](https://cnocr.readthedocs.io/zh-cn/stable/models/) |
20
+ [🕹 模型训练](https://cnocr.readthedocs.io/zh-cn/stable/train/) |
21
21
  [🛀🏻 在线Demo](https://huggingface.co/spaces/breezedeus/CnOCR-Demo) |
22
- [💬 交流群](https://cnocr.readthedocs.io/zh/latest/contact/)
22
+ [💬 交流群](https://www.breezedeus.com/article/join-group)
23
23
 
24
24
  </div>
25
25
 
@@ -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
  主要变更:
@@ -58,7 +68,7 @@
58
68
 
59
69
 
60
70
 
61
- [**CnOCR**](https://github.com/breezedeus/cnocr) 是 **Python 3** 下的**文字识别**(**Optical Character Recognition**,简称**OCR**)工具包,支持**简体中文**、**繁体中文**(部分模型)、**英文**和**数字**的常见字符识别,支持竖排文字的识别。自带了**20+个** [训练好的模型](https://cnocr.readthedocs.io/zh/latest/models/),适用于不同应用场景,安装后即可直接使用。同时,CnOCR也提供简单的[训练命令](https://cnocr.readthedocs.io/zh/latest/train/)供使用者训练自己的模型。欢迎扫码加小助手为好友,备注 `ocr`,小助手会定期统一邀请大家入群:
71
+ [**CnOCR**](https://github.com/breezedeus/cnocr) 是 **Python 3** 下的**文字识别**(**Optical Character Recognition**,简称**OCR**)工具包,支持**简体中文**、**繁体中文**(部分模型)、**英文**和**数字**的常见字符识别,支持竖排文字的识别。自带了**20+个** [训练好的模型](https://cnocr.readthedocs.io/zh-cn/stable/models/),适用于不同应用场景,安装后即可直接使用。同时,CnOCR也提供简单的[训练命令](https://cnocr.readthedocs.io/zh-cn/stable/train/)供使用者训练自己的模型。欢迎扫码加小助手为好友,备注 `ocr`,小助手会定期统一邀请大家入群:
62
72
 
63
73
  <div align="center">
64
74
  <img src="https://huggingface.co/datasets/breezedeus/cnocr-wx-qr-code/resolve/main/wx-qr-code.JPG" alt="微信群二维码" width="300px"/>
@@ -285,7 +295,7 @@ $ pip install cnocr[ort-cpu] -i https://mirrors.aliyun.com/pypi/simple
285
295
  >
286
296
  > 请使用 **Python3**(3.7.\*~3.10.\*之间的版本应该都行),没测过Python2下是否ok。
287
297
 
288
- 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh/latest/install/)。
298
+ 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh-cn/stable/install/)。
289
299
 
290
300
  > **Warning**
291
301
  >
@@ -301,7 +311,7 @@ $ pip install cnocr[ort-cpu] -i https://mirrors.aliyun.com/pypi/simple
301
311
  $ docker pull breezedeus/cnocr:latest
302
312
  ```
303
313
 
304
- 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh/latest/install/)。
314
+ 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh-cn/stable/install/)。
305
315
 
306
316
 
307
317
 
@@ -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
 
@@ -391,7 +401,7 @@ print(ocr_out)
391
401
 
392
402
  相比于 CnOCR V2.2.* 版本,**V2.3** 中的大部分模型都经过了重新训练和精调,精度比旧版模型更高。同时,加入了两个参数量更多的模型系列:
393
403
 
394
- * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,2024 年 2 月都会免费开源。
404
+ * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,后续会免费开源。
395
405
  * `*-densenet_lite_666-gru_large`:**Pro 模型**,购买后可使用。购买链接见文档:
396
406
 
397
407
  **V2.3** 中的模型按使用场景可以分为以下几大类:
@@ -403,7 +413,7 @@ print(ocr_out)
403
413
 
404
414
  > 注意 ⚠️:以上说明仅供参考,具体选择模型时建议以实际效果为准。
405
415
 
406
- 更多说明见:[可用模型](https://cnocr.readthedocs.io/zh/latest/models/)。
416
+ 更多说明见:[可用模型](https://cnocr.readthedocs.io/zh-cn/stable/models/)。
407
417
 
408
418
  | `rec_model_name` | PyTorch 版本 | ONNX 版本 | 模型原始来源 | 模型文件大小 | 支持语言 | 是否支持竖排文字识别 |
409
419
  | ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ----------------------------------- | -------------------- |
@@ -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
 
@@ -447,9 +464,8 @@ print(ocr_out)
447
464
 
448
465
  ## 给作者来杯咖啡
449
466
 
450
- 开源不易,如果此项目对您有帮助,可以考虑 [给作者加点油🥤,鼓鼓气💪🏻](https://cnocr.readthedocs.io/zh/latest/buymeacoffee/) 。
467
+ 开源不易,如果此项目对您有帮助,可以考虑 [给作者加点油🥤,鼓鼓气💪🏻](https://cnocr.readthedocs.io/zh-cn/stable/buymeacoffee/) 。
451
468
 
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.2'
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())
@@ -158,7 +158,7 @@ def main():
158
158
 
159
159
  st.markdown('# 开源Python OCR工具 ' '[CnOCR](https://github.com/breezedeus/cnocr)')
160
160
  st.markdown('> 详细说明参见:[CnOCR 文档](https://cnocr.readthedocs.io/) ;'
161
- '欢迎加入 [交流群](https://cnocr.readthedocs.io/zh/latest/contact/) ;'
161
+ '欢迎加入 [交流群](https://www.breezedeus.com/article/join-group) ;'
162
162
  '作者:[breezedeus](https://github.com/breezedeus) 。')
163
163
  st.markdown('')
164
164
  st.subheader('选择待检测图片')
@@ -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.2
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
@@ -36,7 +36,7 @@ License-File: LICENSE
36
36
  [![Downloads](https://static.pepy.tech/personalized-badge/cnocr?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads)](https://pepy.tech/project/cnocr)
37
37
  [![Visitors](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2Fbreezedeus%2FCnOCR&label=Visitors&countColor=%23f5c791&style=flat&labelStyle=none)](https://visitorbadge.io/status?path=https%3A%2F%2Fgithub.com%2Fbreezedeus%2FCnOCR)
38
38
  [![license](https://img.shields.io/github/license/breezedeus/cnocr)](./LICENSE)
39
- [![Docs](https://readthedocs.org/projects/cnocr/badge/?version=latest)](https://cnocr.readthedocs.io/zh/latest/?badge=latest)
39
+ [![Docs](https://readthedocs.org/projects/cnocr/badge/?version=latest)](https://cnocr.readthedocs.io/zh-cn/stable/?badge=latest)
40
40
  [![PyPI version](https://badge.fury.io/py/cnocr.svg)](https://badge.fury.io/py/cnocr)
41
41
  [![forks](https://img.shields.io/github/forks/breezedeus/cnocr)](https://github.com/breezedeus/cnocr)
42
42
  [![stars](https://img.shields.io/github/stars/breezedeus/cnocr)](https://github.com/breezedeus/cnocr)
@@ -44,12 +44,12 @@ License-File: LICENSE
44
44
  ![last-commit](https://img.shields.io/github/last-commit/breezedeus/cnocr)
45
45
  [![Twitter](https://img.shields.io/twitter/url?url=https%3A%2F%2Ftwitter.com%2Fbreezedeus)](https://twitter.com/breezedeus)
46
46
 
47
- [📖 文档](https://cnocr.readthedocs.io/zh/latest/) |
48
- [🛠️ 安装](https://cnocr.readthedocs.io/zh/latest/install/) |
49
- [🧳 可用模型](https://cnocr.readthedocs.io/zh/latest/models/) |
50
- [🕹 模型训练](https://cnocr.readthedocs.io/zh/latest/train/) |
47
+ [📖 文档](https://cnocr.readthedocs.io/zh-cn/stable/) |
48
+ [🛠️ 安装](https://cnocr.readthedocs.io/zh-cn/stable/install/) |
49
+ [🧳 可用模型](https://cnocr.readthedocs.io/zh-cn/stable/models/) |
50
+ [🕹 模型训练](https://cnocr.readthedocs.io/zh-cn/stable/train/) |
51
51
  [🛀🏻 在线Demo](https://huggingface.co/spaces/breezedeus/CnOCR-Demo) |
52
- [💬 交流群](https://cnocr.readthedocs.io/zh/latest/contact/)
52
+ [💬 交流群](https://www.breezedeus.com/article/join-group)
53
53
 
54
54
  </div>
55
55
 
@@ -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
  主要变更:
@@ -88,7 +98,7 @@ License-File: LICENSE
88
98
 
89
99
 
90
100
 
91
- [**CnOCR**](https://github.com/breezedeus/cnocr) 是 **Python 3** 下的**文字识别**(**Optical Character Recognition**,简称**OCR**)工具包,支持**简体中文**、**繁体中文**(部分模型)、**英文**和**数字**的常见字符识别,支持竖排文字的识别。自带了**20+个** [训练好的模型](https://cnocr.readthedocs.io/zh/latest/models/),适用于不同应用场景,安装后即可直接使用。同时,CnOCR也提供简单的[训练命令](https://cnocr.readthedocs.io/zh/latest/train/)供使用者训练自己的模型。欢迎扫码加小助手为好友,备注 `ocr`,小助手会定期统一邀请大家入群:
101
+ [**CnOCR**](https://github.com/breezedeus/cnocr) 是 **Python 3** 下的**文字识别**(**Optical Character Recognition**,简称**OCR**)工具包,支持**简体中文**、**繁体中文**(部分模型)、**英文**和**数字**的常见字符识别,支持竖排文字的识别。自带了**20+个** [训练好的模型](https://cnocr.readthedocs.io/zh-cn/stable/models/),适用于不同应用场景,安装后即可直接使用。同时,CnOCR也提供简单的[训练命令](https://cnocr.readthedocs.io/zh-cn/stable/train/)供使用者训练自己的模型。欢迎扫码加小助手为好友,备注 `ocr`,小助手会定期统一邀请大家入群:
92
102
 
93
103
  <div align="center">
94
104
  <img src="https://huggingface.co/datasets/breezedeus/cnocr-wx-qr-code/resolve/main/wx-qr-code.JPG" alt="微信群二维码" width="300px"/>
@@ -315,7 +325,7 @@ $ pip install cnocr[ort-cpu] -i https://mirrors.aliyun.com/pypi/simple
315
325
  >
316
326
  > 请使用 **Python3**(3.7.\*~3.10.\*之间的版本应该都行),没测过Python2下是否ok。
317
327
 
318
- 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh/latest/install/)。
328
+ 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh-cn/stable/install/)。
319
329
 
320
330
  > **Warning**
321
331
  >
@@ -331,7 +341,7 @@ $ pip install cnocr[ort-cpu] -i https://mirrors.aliyun.com/pypi/simple
331
341
  $ docker pull breezedeus/cnocr:latest
332
342
  ```
333
343
 
334
- 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh/latest/install/)。
344
+ 更多说明可见 [安装文档](https://cnocr.readthedocs.io/zh-cn/stable/install/)。
335
345
 
336
346
 
337
347
 
@@ -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
 
@@ -421,7 +431,7 @@ print(ocr_out)
421
431
 
422
432
  相比于 CnOCR V2.2.* 版本,**V2.3** 中的大部分模型都经过了重新训练和精调,精度比旧版模型更高。同时,加入了两个参数量更多的模型系列:
423
433
 
424
- * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,2024 年 2 月都会免费开源。
434
+ * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,后续会免费开源。
425
435
  * `*-densenet_lite_666-gru_large`:**Pro 模型**,购买后可使用。购买链接见文档:
426
436
 
427
437
  **V2.3** 中的模型按使用场景可以分为以下几大类:
@@ -433,7 +443,7 @@ print(ocr_out)
433
443
 
434
444
  > 注意 ⚠️:以上说明仅供参考,具体选择模型时建议以实际效果为准。
435
445
 
436
- 更多说明见:[可用模型](https://cnocr.readthedocs.io/zh/latest/models/)。
446
+ 更多说明见:[可用模型](https://cnocr.readthedocs.io/zh-cn/stable/models/)。
437
447
 
438
448
  | `rec_model_name` | PyTorch 版本 | ONNX 版本 | 模型原始来源 | 模型文件大小 | 支持语言 | 是否支持竖排文字识别 |
439
449
  | ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ----------------------------------- | -------------------- |
@@ -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
 
@@ -477,11 +494,10 @@ print(ocr_out)
477
494
 
478
495
  ## 给作者来杯咖啡
479
496
 
480
- 开源不易,如果此项目对您有帮助,可以考虑 [给作者加点油🥤,鼓鼓气💪🏻](https://cnocr.readthedocs.io/zh/latest/buymeacoffee/) 。
497
+ 开源不易,如果此项目对您有帮助,可以考虑 [给作者加点油🥤,鼓鼓气💪🏻](https://cnocr.readthedocs.io/zh-cn/stable/buymeacoffee/) 。
481
498
 
482
499
  ---
483
500
 
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