cnocr 2.2.4.2__tar.gz → 2.3.0.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 (61) hide show
  1. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/PKG-INFO +68 -20
  2. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/README.md +65 -19
  3. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/__init__.py +2 -2
  4. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/__version__.py +1 -1
  5. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/app.py +1 -1
  6. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/cli.py +32 -9
  7. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/cn_ocr.py +6 -6
  8. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/consts.py +82 -51
  9. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/data_utils/transforms.py +45 -5
  10. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/dataset.py +38 -25
  11. cnocr-2.3.0.1/cnocr/dataset_utils.py +108 -0
  12. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/label_cn.txt +30 -21
  13. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/models/ocr_model.py +2 -1
  14. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/ppocr/pp_recognizer.py +10 -5
  15. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/ppocr/utility.py +8 -3
  16. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/recognizer.py +19 -12
  17. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/trainer.py +3 -0
  18. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/utils.py +18 -0
  19. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr.egg-info/PKG-INFO +68 -20
  20. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr.egg-info/SOURCES.txt +1 -0
  21. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr.egg-info/entry_points.txt +1 -0
  22. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr.egg-info/requires.txt +1 -0
  23. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/setup.py +1 -1
  24. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/tests/test_cnocr.py +5 -5
  25. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/tests/test_pytorch.py +1 -1
  26. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/tests/test_trainer.py +1 -1
  27. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/LICENSE +0 -0
  28. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/classification/__init__.py +0 -0
  29. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/classification/dataset.py +0 -0
  30. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/classification/image_classifier.py +0 -0
  31. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/clf_cli.py +0 -0
  32. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/data_utils/__init__.py +0 -0
  33. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/data_utils/aug.py +0 -0
  34. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/data_utils/block_shuffle.py +0 -0
  35. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/data_utils/utils.py +0 -0
  36. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/gradio_app.py +0 -0
  37. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/gradio_app2.py +0 -0
  38. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/label_number.txt +0 -0
  39. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/line_split.py +0 -0
  40. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/lr_scheduler.py +0 -0
  41. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/models/__init__.py +0 -0
  42. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/models/ctc.py +0 -0
  43. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/models/densenet.py +0 -0
  44. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/models/mobilenet.py +0 -0
  45. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/ppocr/__init__.py +0 -0
  46. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/ppocr/consts.py +0 -0
  47. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/ppocr/postprocess/__init__.py +0 -0
  48. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/ppocr/postprocess/rec_postprocess.py +0 -0
  49. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/ppocr/utils/__init__.py +0 -0
  50. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/ppocr/utils/chinese_cht_dict.txt +0 -0
  51. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/ppocr/utils/en_dict.txt +0 -0
  52. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/ppocr/utils/ppocr_keys_v1.txt +0 -0
  53. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr/serve.py +0 -0
  54. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr.egg-info/dependency_links.txt +0 -0
  55. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr.egg-info/not-zip-safe +0 -0
  56. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/cnocr.egg-info/top_level.txt +0 -0
  57. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/setup.cfg +0 -0
  58. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/tests/test_dataset.py +0 -0
  59. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/tests/test_models.py +0 -0
  60. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/tests/test_ppocr.py +0 -0
  61. {cnocr-2.2.4.2 → cnocr-2.3.0.1}/tests/test_transforms.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cnocr
3
- Version: 2.2.4.2
3
+ Version: 2.3.0.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
@@ -33,6 +33,7 @@ License-File: LICENSE
33
33
  <div>&nbsp;</div>
34
34
 
35
35
  [![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)
36
+ [![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)
36
37
  [![license](https://img.shields.io/github/license/breezedeus/cnocr)](./LICENSE)
37
38
  [![Docs](https://readthedocs.org/projects/cnocr/badge/?version=latest)](https://cnocr.readthedocs.io/zh/latest/?badge=latest)
38
39
  [![PyPI version](https://badge.fury.io/py/cnocr.svg)](https://badge.fury.io/py/cnocr)
@@ -67,15 +68,23 @@ License-File: LICENSE
67
68
  ---
68
69
  </div>
69
70
 
70
- ### [Update 2023.09.27]:发布 V2.2.4
71
+ ### [Update 2023.12.24]:发布 V2.3
71
72
 
72
73
  主要变更:
73
- * 加入了纯数字识别系列模型 `number-*`(见 [识别模型列表](#可使用的识别模型)),可用于纯数字识别场景,如银行卡识别、身份证识别、硬币年份识别等;
74
- * 对各个包的新版做了接口适配,如 `pytorch_lightning`、`onnxruntime`、`pillow`等;
75
- * 优化了训练过程使用的数据增强方式,并借鉴了**Nougat** 中的数据增强方法;
76
- * 增加了对更大模型的支持,如 `densenet-lite-666`、`gru_large` 等;
77
- * 以前的 `*-gru` 系列模型,现在也有 ONNX 版了;
78
- * 修复了一堆的bugs,如 `val-complete_match-epoch` 训练过程一直为 `0` 等。
74
+
75
+ * 重新训练了所有的模型,比上一版精度更高。
76
+ * 按使用场景把模型分为几大类场景(见 [识别模型列表](#可使用的识别模型)):
77
+ * `scene`:场景图片,适合识别一般拍照图片中的文字。此类模型以 `scene-` 开头,如模型 `scene-densenet_lite_136-gru`。
78
+ * `doc`:文档图片,适合识别规则文档的截图图片,如书籍扫描件等。此类模型以 `doc-` 开头,如模型 `doc-densenet_lite_136-gru`。
79
+ * `number`:仅识别**纯数字**(只能识别 `0~9` 十个数字)图片,适合银行卡号、身份证号等场景。此类模型以 `number-` 开头,如模型 `number-densenet_lite_136-gru`。
80
+ * `general`: 通用场景,适合图片无明显倾向的一般图片。此类模型无特定开头,与旧版模型名称保持一致,如模型 `densenet_lite_136-gru`。
81
+ > 注意 ⚠️:以上说明仅为参考,具体选择模型时建议以实际效果为准。
82
+ * 加入了两个更大的系列模型:
83
+ * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,一个月后会免费开源。
84
+ * `*-densenet_lite_666-gru_large`:Pro 模型,购买后可使用。
85
+
86
+ 更多细节请参考:[CnOCR V2.3 新版发布:模型更好、更多、更大 | Breezedeus.com](https://www.breezedeus.com/article/cnocr-v2.3-better-more)。
87
+
79
88
 
80
89
 
81
90
  [**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`,小助手会定期统一邀请大家入群:
@@ -85,7 +94,16 @@ License-File: LICENSE
85
94
  </div>
86
95
 
87
96
 
88
- 作者也维护 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) ,这里面的提问会较快得到作者的回复,欢迎加入。**知识星球私享群**也会陆续发布一些CnOCR/CnSTD相关的私有资料,包括[**更详细的训练教程**](https://articles.zsxq.com/id_u6b4u0wrf46e.html),**未公开的模型**,**不同应用场景的调用代码**,使用过程中遇到的难题解答等。本群也会发布OCR/STD相关的最新研究资料。此外,**私享群中作者每月提供两次免费特有数据的训练服务**。
97
+ 作者也维护 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) ,这里面的提问会较快得到作者的回复,欢迎加入。**知识星球会员** 可享受以下福利:
98
+
99
+ - 可免费下载部分**未开源的付费模型**;
100
+ - 购买其他所有的付费模型一律八折优化;
101
+ - 作者快速回复使用过程中遇到的各种困难;
102
+ - 作者每月提供两次免费特有数据的训练服务。
103
+ - 星球会陆续发布一些CnOCR/CnSTD相关的私有资料;
104
+ - 星球会持续发布 OCR/STD/CV 等相关的最新研究资料。
105
+
106
+
89
107
 
90
108
  ## 详细文档
91
109
 
@@ -278,7 +296,15 @@ $ pip install cnocr[ort-gpu]
278
296
 
279
297
 
280
298
 
281
- 安装速度慢的话,可以指定国内的安装源,如使用豆瓣源:
299
+ 如果要训练自己的模型,,可以使用以下命令安装:
300
+
301
+ ```bash
302
+ $ pip install cnocr[dev]
303
+ ```
304
+
305
+
306
+
307
+ 安装速度慢的话,可以指定国内的安装源,如使用阿里云的安装源:
282
308
 
283
309
  ```bash
284
310
  $ pip install cnocr[ort-cpu] -i https://mirrors.aliyun.com/pypi/simple
@@ -363,7 +389,7 @@ print(ocr_out)
363
389
 
364
390
  ### 可使用的检测模型
365
391
 
366
- 参考CnSTD的下载方式。
392
+ 具体参考 [CnSTD的下载说明](https://github.com/breezedeus/CnSTD?tab=readme-ov-file#%E5%B7%B2%E6%9C%89std%E6%A8%A1%E5%9E%8B)。
367
393
 
368
394
  | `det_model_name` | PyTorch 版本 | ONNX 版本 | 模型原始来源 | 模型文件大小 | 支持语言 | 是否支持竖排文字识别 |
369
395
  | ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ------------------------------ | -------------------- |
@@ -382,17 +408,36 @@ print(ocr_out)
382
408
 
383
409
  ### 可使用的识别模型
384
410
 
411
+ 相比于 CnOCR V2.2.* 版本,**V2.3** 中的大部分模型都经过了重新训练和精调,精度比旧版模型更高。同时,加入了两个参数量更多的模型系列:
412
+
413
+ * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,2024 年 2 月都会免费开源。
414
+ * `*-densenet_lite_666-gru_large`:**Pro 模型**,购买后可使用。购买链接见文档:
415
+
416
+ **V2.3** 中的模型按使用场景可以分为以下几大类:
417
+
418
+ * `scene`:场景图片,适合识别一般拍照图片中的文字。此类模型以 `scene-` 开头,如模型 `scene-densenet_lite_136-gru`。
419
+ * `doc`:文档图片,适合识别规则文档的截图图片,如书籍扫描件等。此类模型以 `doc-` 开头,如模型 `doc-densenet_lite_136-gru`。
420
+ * `number`:仅识别**纯数字**(只能识别 `0~9` 十个数字)图片,适合银行卡号、身份证号等场景。此类模型以 `number-` 开头,如模型 `number-densenet_lite_136-gru`。
421
+ * `general`: 通用场景,适合图片无明显倾向的一般图片。此类模型无特定开头,与旧版模型名称保持一致,如模型 `densenet_lite_136-gru`。
422
+
423
+ > 注意 ⚠️:以上说明仅供参考,具体选择模型时建议以实际效果为准。
424
+
425
+ 更多说明见:[可用模型](https://cnocr.readthedocs.io/zh/latest/models/)。
426
+
385
427
  | `rec_model_name` | PyTorch 版本 | ONNX 版本 | 模型原始来源 | 模型文件大小 | 支持语言 | 是否支持竖排文字识别 |
386
428
  | ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ----------------------------------- | -------------------- |
429
+ | **densenet_lite_136-gru** 🆕 | √ | √ | cnocr | 12 M | 简体中文、英文、数字 | X |
430
+ | **scene-densenet_lite_136-gru** 🆕 | √ | √ | cnocr | 12 M | 简体中文、英文、数字 | X |
431
+ | **doc-densenet_lite_136-gru** 🆕 | √ | √ | cnocr | 12 M | 简体中文、英文、数字 | X |
432
+ | **densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享,2 月开源) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
433
+ | **scene-densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享,2 月开源) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
434
+ | **doc-densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享,2 月开源) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
435
+ | **densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://gf.bilibili.com/item/detail/1104812055)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
436
+ | **scene-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://gf.bilibili.com/item/detail/1104815055)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
437
+ | **doc-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://gf.bilibili.com/item/detail/1104820055)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
387
438
  | **number-densenet_lite_136-fc** 🆕 | √ | √ | cnocr | 2.7 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
388
- | **number-densenet_lite_136-gru** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 5.5 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
389
- | **number-densenet_lite_666-gru_large** 🆕 <br />([购买链接](https://gf.bilibili.com/item/detail/1104055055)) | √ | √ | cnocr | M | **纯数字**(仅包含 `0~9` 十个数字) | X |
390
- | densenet_lite_114-fc | √ | √ | cnocr | 4.9 M | 简体中文、英文、数字 | X |
391
- | densenet_lite_124-fc | √ | √ | cnocr | 5.1 M | 简体中文、英文、数字 | X |
392
- | densenet_lite_134-fc | √ | √ | cnocr | 5.4 M | 简体中文、英文、数字 | X |
393
- | densenet_lite_136-fc | √ | √ | cnocr | 5.9 M | 简体中文、英文、数字 | X |
394
- | densenet_lite_134-gru | √ | √ | cnocr | 11 M | 简体中文、英文、数字 | X |
395
- | densenet_lite_136-gru | √ | √ | cnocr | 12 M | 简体中文、英文、数字 | X |
439
+ | **number-densenet_lite_136-gru** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享,2 月开源) | √ | √ | cnocr | 5.5 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
440
+ | **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 |
396
441
  | ch_PP-OCRv3 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
397
442
  | ch_ppocr_mobile_v2.0 | X | √ | ppocr | 4.2 M | 简体中文、英文、数字 | √ |
398
443
  | en_PP-OCRv3 | X | √ | ppocr | 8.5 M | **英文**、数字 | √ |
@@ -414,7 +459,8 @@ print(ocr_out)
414
459
  * [x] 基于 PyTorch 训练更高效的模型
415
460
  * [x] 支持列格式的文字识别
416
461
  * [x] 打通与 [CnSTD](https://github.com/breezedeus/cnstd) 的无缝衔接(since `V2.2`)
417
- * [ ] 支持更多的应用场景,如公式识别、表格识别、版面分析等
462
+ * [ ] 模型精度进一步优化
463
+ * [ ] 支持更多的应用场景
418
464
 
419
465
 
420
466
 
@@ -426,3 +472,5 @@ print(ocr_out)
426
472
 
427
473
  官方代码库:[https://github.com/breezedeus/cnocr](https://github.com/breezedeus/cnocr)。
428
474
 
475
+
476
+
@@ -3,6 +3,7 @@
3
3
  <div>&nbsp;</div>
4
4
 
5
5
  [![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)
6
+ [![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)
6
7
  [![license](https://img.shields.io/github/license/breezedeus/cnocr)](./LICENSE)
7
8
  [![Docs](https://readthedocs.org/projects/cnocr/badge/?version=latest)](https://cnocr.readthedocs.io/zh/latest/?badge=latest)
8
9
  [![PyPI version](https://badge.fury.io/py/cnocr.svg)](https://badge.fury.io/py/cnocr)
@@ -37,15 +38,23 @@
37
38
  ---
38
39
  </div>
39
40
 
40
- ### [Update 2023.09.27]:发布 V2.2.4
41
+ ### [Update 2023.12.24]:发布 V2.3
41
42
 
42
43
  主要变更:
43
- * 加入了纯数字识别系列模型 `number-*`(见 [识别模型列表](#可使用的识别模型)),可用于纯数字识别场景,如银行卡识别、身份证识别、硬币年份识别等;
44
- * 对各个包的新版做了接口适配,如 `pytorch_lightning`、`onnxruntime`、`pillow`等;
45
- * 优化了训练过程使用的数据增强方式,并借鉴了**Nougat** 中的数据增强方法;
46
- * 增加了对更大模型的支持,如 `densenet-lite-666`、`gru_large` 等;
47
- * 以前的 `*-gru` 系列模型,现在也有 ONNX 版了;
48
- * 修复了一堆的bugs,如 `val-complete_match-epoch` 训练过程一直为 `0` 等。
44
+
45
+ * 重新训练了所有的模型,比上一版精度更高。
46
+ * 按使用场景把模型分为几大类场景(见 [识别模型列表](#可使用的识别模型)):
47
+ * `scene`:场景图片,适合识别一般拍照图片中的文字。此类模型以 `scene-` 开头,如模型 `scene-densenet_lite_136-gru`。
48
+ * `doc`:文档图片,适合识别规则文档的截图图片,如书籍扫描件等。此类模型以 `doc-` 开头,如模型 `doc-densenet_lite_136-gru`。
49
+ * `number`:仅识别**纯数字**(只能识别 `0~9` 十个数字)图片,适合银行卡号、身份证号等场景。此类模型以 `number-` 开头,如模型 `number-densenet_lite_136-gru`。
50
+ * `general`: 通用场景,适合图片无明显倾向的一般图片。此类模型无特定开头,与旧版模型名称保持一致,如模型 `densenet_lite_136-gru`。
51
+ > 注意 ⚠️:以上说明仅为参考,具体选择模型时建议以实际效果为准。
52
+ * 加入了两个更大的系列模型:
53
+ * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,一个月后会免费开源。
54
+ * `*-densenet_lite_666-gru_large`:Pro 模型,购买后可使用。
55
+
56
+ 更多细节请参考:[CnOCR V2.3 新版发布:模型更好、更多、更大 | Breezedeus.com](https://www.breezedeus.com/article/cnocr-v2.3-better-more)。
57
+
49
58
 
50
59
 
51
60
  [**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`,小助手会定期统一邀请大家入群:
@@ -55,7 +64,16 @@
55
64
  </div>
56
65
 
57
66
 
58
- 作者也维护 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) ,这里面的提问会较快得到作者的回复,欢迎加入。**知识星球私享群**也会陆续发布一些CnOCR/CnSTD相关的私有资料,包括[**更详细的训练教程**](https://articles.zsxq.com/id_u6b4u0wrf46e.html),**未公开的模型**,**不同应用场景的调用代码**,使用过程中遇到的难题解答等。本群也会发布OCR/STD相关的最新研究资料。此外,**私享群中作者每月提供两次免费特有数据的训练服务**。
67
+ 作者也维护 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) ,这里面的提问会较快得到作者的回复,欢迎加入。**知识星球会员** 可享受以下福利:
68
+
69
+ - 可免费下载部分**未开源的付费模型**;
70
+ - 购买其他所有的付费模型一律八折优化;
71
+ - 作者快速回复使用过程中遇到的各种困难;
72
+ - 作者每月提供两次免费特有数据的训练服务。
73
+ - 星球会陆续发布一些CnOCR/CnSTD相关的私有资料;
74
+ - 星球会持续发布 OCR/STD/CV 等相关的最新研究资料。
75
+
76
+
59
77
 
60
78
  ## 详细文档
61
79
 
@@ -248,7 +266,15 @@ $ pip install cnocr[ort-gpu]
248
266
 
249
267
 
250
268
 
251
- 安装速度慢的话,可以指定国内的安装源,如使用豆瓣源:
269
+ 如果要训练自己的模型,,可以使用以下命令安装:
270
+
271
+ ```bash
272
+ $ pip install cnocr[dev]
273
+ ```
274
+
275
+
276
+
277
+ 安装速度慢的话,可以指定国内的安装源,如使用阿里云的安装源:
252
278
 
253
279
  ```bash
254
280
  $ pip install cnocr[ort-cpu] -i https://mirrors.aliyun.com/pypi/simple
@@ -333,7 +359,7 @@ print(ocr_out)
333
359
 
334
360
  ### 可使用的检测模型
335
361
 
336
- 参考CnSTD的下载方式。
362
+ 具体参考 [CnSTD的下载说明](https://github.com/breezedeus/CnSTD?tab=readme-ov-file#%E5%B7%B2%E6%9C%89std%E6%A8%A1%E5%9E%8B)。
337
363
 
338
364
  | `det_model_name` | PyTorch 版本 | ONNX 版本 | 模型原始来源 | 模型文件大小 | 支持语言 | 是否支持竖排文字识别 |
339
365
  | ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ------------------------------ | -------------------- |
@@ -352,17 +378,36 @@ print(ocr_out)
352
378
 
353
379
  ### 可使用的识别模型
354
380
 
381
+ 相比于 CnOCR V2.2.* 版本,**V2.3** 中的大部分模型都经过了重新训练和精调,精度比旧版模型更高。同时,加入了两个参数量更多的模型系列:
382
+
383
+ * `*-densenet_lite_246-gru_base`:优先供 **知识星球** [**CnOCR/CnSTD私享群**](https://t.zsxq.com/FEYZRJQ) 会员使用,2024 年 2 月都会免费开源。
384
+ * `*-densenet_lite_666-gru_large`:**Pro 模型**,购买后可使用。购买链接见文档:
385
+
386
+ **V2.3** 中的模型按使用场景可以分为以下几大类:
387
+
388
+ * `scene`:场景图片,适合识别一般拍照图片中的文字。此类模型以 `scene-` 开头,如模型 `scene-densenet_lite_136-gru`。
389
+ * `doc`:文档图片,适合识别规则文档的截图图片,如书籍扫描件等。此类模型以 `doc-` 开头,如模型 `doc-densenet_lite_136-gru`。
390
+ * `number`:仅识别**纯数字**(只能识别 `0~9` 十个数字)图片,适合银行卡号、身份证号等场景。此类模型以 `number-` 开头,如模型 `number-densenet_lite_136-gru`。
391
+ * `general`: 通用场景,适合图片无明显倾向的一般图片。此类模型无特定开头,与旧版模型名称保持一致,如模型 `densenet_lite_136-gru`。
392
+
393
+ > 注意 ⚠️:以上说明仅供参考,具体选择模型时建议以实际效果为准。
394
+
395
+ 更多说明见:[可用模型](https://cnocr.readthedocs.io/zh/latest/models/)。
396
+
355
397
  | `rec_model_name` | PyTorch 版本 | ONNX 版本 | 模型原始来源 | 模型文件大小 | 支持语言 | 是否支持竖排文字识别 |
356
398
  | ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ----------------------------------- | -------------------- |
399
+ | **densenet_lite_136-gru** 🆕 | √ | √ | cnocr | 12 M | 简体中文、英文、数字 | X |
400
+ | **scene-densenet_lite_136-gru** 🆕 | √ | √ | cnocr | 12 M | 简体中文、英文、数字 | X |
401
+ | **doc-densenet_lite_136-gru** 🆕 | √ | √ | cnocr | 12 M | 简体中文、英文、数字 | X |
402
+ | **densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享,2 月开源) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
403
+ | **scene-densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享,2 月开源) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
404
+ | **doc-densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享,2 月开源) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
405
+ | **densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://gf.bilibili.com/item/detail/1104812055)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
406
+ | **scene-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://gf.bilibili.com/item/detail/1104815055)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
407
+ | **doc-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://gf.bilibili.com/item/detail/1104820055)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
357
408
  | **number-densenet_lite_136-fc** 🆕 | √ | √ | cnocr | 2.7 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
358
- | **number-densenet_lite_136-gru** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 5.5 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
359
- | **number-densenet_lite_666-gru_large** 🆕 <br />([购买链接](https://gf.bilibili.com/item/detail/1104055055)) | √ | √ | cnocr | M | **纯数字**(仅包含 `0~9` 十个数字) | X |
360
- | densenet_lite_114-fc | √ | √ | cnocr | 4.9 M | 简体中文、英文、数字 | X |
361
- | densenet_lite_124-fc | √ | √ | cnocr | 5.1 M | 简体中文、英文、数字 | X |
362
- | densenet_lite_134-fc | √ | √ | cnocr | 5.4 M | 简体中文、英文、数字 | X |
363
- | densenet_lite_136-fc | √ | √ | cnocr | 5.9 M | 简体中文、英文、数字 | X |
364
- | densenet_lite_134-gru | √ | √ | cnocr | 11 M | 简体中文、英文、数字 | X |
365
- | densenet_lite_136-gru | √ | √ | cnocr | 12 M | 简体中文、英文、数字 | X |
409
+ | **number-densenet_lite_136-gru** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享,2 月开源) | √ | √ | cnocr | 5.5 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
410
+ | **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 |
366
411
  | ch_PP-OCRv3 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
367
412
  | ch_ppocr_mobile_v2.0 | X | √ | ppocr | 4.2 M | 简体中文、英文、数字 | √ |
368
413
  | en_PP-OCRv3 | X | √ | ppocr | 8.5 M | **英文**、数字 | √ |
@@ -384,7 +429,8 @@ print(ocr_out)
384
429
  * [x] 基于 PyTorch 训练更高效的模型
385
430
  * [x] 支持列格式的文字识别
386
431
  * [x] 打通与 [CnSTD](https://github.com/breezedeus/cnstd) 的无缝衔接(since `V2.2`)
387
- * [ ] 支持更多的应用场景,如公式识别、表格识别、版面分析等
432
+ * [ ] 模型精度进一步优化
433
+ * [ ] 支持更多的应用场景
388
434
 
389
435
 
390
436
 
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- # Copyright (C) 2021, [Breezedeus](https://github.com/breezedeus).
2
+ # Copyright (C) 2021-2023, [Breezedeus](https://github.com/breezedeus).
3
3
  # Licensed to the Apache Software Foundation (ASF) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -26,7 +26,7 @@ from .consts import (
26
26
  NUMBERS,
27
27
  ENG_LETTERS,
28
28
  )
29
- from .utils import read_img
29
+ from .utils import read_img, set_logger
30
30
  from .cn_ocr import CnOcr
31
31
  from .recognizer import gen_model
32
32
  from .line_split import line_split
@@ -17,4 +17,4 @@
17
17
  # specific language governing permissions and limitations
18
18
  # under the License.
19
19
 
20
- __version__ = '2.2.4.2'
20
+ __version__ = '2.3.0.1'
@@ -134,7 +134,7 @@ def main():
134
134
 
135
135
  all_models = list(REC_AVAILABLE_MODELS.all_models())
136
136
  all_models.sort()
137
- idx = all_models.index(('densenet_lite_136-fc', 'onnx'))
137
+ idx = all_models.index(('densenet_lite_136-gru', 'onnx'))
138
138
  rec_model_name = st.sidebar.selectbox('选择识别模型', all_models, index=idx)
139
139
 
140
140
  st.sidebar.subheader('检测参数')
@@ -30,6 +30,7 @@ from multiprocessing import Process
30
30
  import subprocess
31
31
 
32
32
  import click
33
+ import numpy as np
33
34
  import torchmetrics
34
35
  from torchvision import transforms as T
35
36
  import torch
@@ -42,9 +43,9 @@ from cnocr.utils import (
42
43
  save_img,
43
44
  read_img,
44
45
  draw_ocr_results,
46
+ read_charset,
45
47
  )
46
48
  from cnocr.data_utils.aug import NormalizeAug
47
- from cnocr.dataset import OcrDataModule
48
49
  from cnocr.trainer import PlTrainer, resave_model, Metrics
49
50
  from cnocr import CnOcr, gen_model
50
51
  from cnocr.recognizer import Recognizer
@@ -52,7 +53,7 @@ from cnocr.recognizer import Recognizer
52
53
  _CONTEXT_SETTINGS = {"help_option_names": ['-h', '--help']}
53
54
  logger = set_logger(log_level=logging.INFO)
54
55
 
55
- DEFAULT_MODEL_NAME = 'densenet_lite_136-fc'
56
+ DEFAULT_MODEL_NAME = 'densenet_lite_136-gru'
56
57
  LEGAL_MODEL_NAMES = {
57
58
  enc_name + '-' + dec_name
58
59
  for enc_name in ENCODER_CONFIGS.keys()
@@ -86,6 +87,9 @@ def cli():
86
87
  required=True,
87
88
  help='识别模型训练使用的json配置文件,参考 `docs/examples/train_config.json`',
88
89
  )
90
+ @click.option(
91
+ "--finetuning", is_flag=True, help="是否为精调模式(精调模式使用更温柔的transform)。默认为 `False`",
92
+ )
89
93
  @click.option(
90
94
  '-r',
91
95
  '--resume-from-checkpoint',
@@ -105,11 +109,19 @@ def train(
105
109
  rec_model_name,
106
110
  index_dir,
107
111
  train_config_fp,
112
+ finetuning,
108
113
  resume_from_checkpoint,
109
114
  pretrained_model_fp,
110
115
  ):
111
116
  """训练识别模型"""
112
- from cnocr.data_utils.transforms import train_transform, test_transform
117
+ from cnocr.dataset import OcrDataModule
118
+
119
+ from cnocr.data_utils.transforms import (
120
+ train_transform,
121
+ ft_transform,
122
+ test_transform,
123
+ )
124
+
113
125
  check_model_name(rec_model_name)
114
126
  # train_transform = T.Compose(
115
127
  # [
@@ -135,7 +147,7 @@ def train(
135
147
  index_dir=index_dir,
136
148
  vocab_fp=train_config['vocab_fp'],
137
149
  img_folder=train_config['img_folder'],
138
- train_transforms=train_transform,
150
+ train_transforms=train_transform if not finetuning else ft_transform,
139
151
  val_transforms=val_transform,
140
152
  batch_size=train_config['batch_size'],
141
153
  train_bucket_size=train_config.get('train_bucket_size'),
@@ -239,6 +251,9 @@ def visualize_example(example, fp_prefix):
239
251
  @click.option(
240
252
  "--draw-font-path", default='./docs/fonts/simfang.ttf', help="画出检测与识别效果图时使用的字体文件",
241
253
  )
254
+ @click.option(
255
+ "--verbose", is_flag=True, default=False, help="是否打印详细日志信息。默认值为 `False`",
256
+ )
242
257
  def predict(
243
258
  rec_model_name,
244
259
  rec_model_backend,
@@ -251,8 +266,14 @@ def predict(
251
266
  single_line,
252
267
  draw_results_dir,
253
268
  draw_font_path,
269
+ verbose,
254
270
  ):
255
- """模型预测"""
271
+ """模型预测""",
272
+ if verbose:
273
+ logger = set_logger(log_level=logging.DEBUG)
274
+ else:
275
+ logger = set_logger(log_level=logging.INFO)
276
+
256
277
  fp_list = []
257
278
  if os.path.isfile(img_file_or_dir):
258
279
  fp_list.append(img_file_or_dir)
@@ -381,6 +402,11 @@ def evaluate(
381
402
  verbose,
382
403
  ):
383
404
  """评估模型效果。检测模型使用 `det_model_name='naive_det'` 。"""
405
+ if verbose:
406
+ logger = set_logger(log_level=logging.DEBUG)
407
+ else:
408
+ logger = set_logger(log_level=logging.INFO)
409
+
384
410
  ocr = CnOcr(
385
411
  rec_model_name=rec_model_name,
386
412
  rec_model_backend=rec_model_backend,
@@ -392,10 +418,7 @@ def evaluate(
392
418
 
393
419
  fn_labels_list = read_input_file(eval_index_fp)
394
420
 
395
- metrics_config = {
396
- "complete_match": {},
397
- "cer": {}
398
- }
421
+ metrics_config = {"complete_match": {}, "cer": {}}
399
422
  metrics = Metrics.from_config(metrics_config)
400
423
  cer = torchmetrics.text.CharErrorRate()
401
424
  miss_cnt, redundant_cnt = Counter(), Counter()
@@ -62,7 +62,7 @@ class OcrResult(object):
62
62
  class CnOcr(object):
63
63
  def __init__(
64
64
  self,
65
- rec_model_name: str = 'densenet_lite_136-fc',
65
+ rec_model_name: str = 'densenet_lite_136-gru',
66
66
  *,
67
67
  det_model_name: str = 'ch_PP-OCRv3_det',
68
68
  cand_alphabet: Optional[Union[Collection, str]] = None,
@@ -82,7 +82,7 @@ class CnOcr(object):
82
82
  识别模型初始化函数。
83
83
 
84
84
  Args:
85
- rec_model_name (str): 识别模型名称。默认为 `densenet_lite_136-fc`
85
+ rec_model_name (str): 识别模型名称。默认为 `densenet_lite_136-gru`
86
86
  det_model_name (str): 检测模型名称。默认为 `ch_PP-OCRv3_det`
87
87
  cand_alphabet (Optional[Union[Collection, str]]): 待识别字符所在的候选集合。默认为 `None`,表示不限定识别字符范围
88
88
  context (str): 'cpu', or 'gpu'。表明预测时是使用CPU还是GPU。默认为 `cpu`。
@@ -94,7 +94,7 @@ class CnOcr(object):
94
94
  若训练的自有模型更改了字符集,看通过此参数传入新的字符集文件路径。
95
95
  rec_more_configs (Optional[Dict[str, Any]]): 识别模型初始化时传入的其他参数。
96
96
  rec_root (Union[str, Path]): 识别模型文件所在的根目录。
97
- Linux/Mac下默认值为 `~/.cnocr`,表示模型文件所处文件夹类似 `~/.cnocr/2.2/densenet_lite_136-fc`。
97
+ Linux/Mac下默认值为 `~/.cnocr`,表示模型文件所处文件夹类似 `~/.cnocr/2.3/densenet_lite_136-gru`。
98
98
  Windows下默认值为 `C:/Users/<username>/AppData/Roaming/cnocr`。
99
99
  det_model_fp (Optional[str]): 如果不使用系统自带的检测模型,可以通过此参数直接指定所使用的模型文件('.ckpt' 文件)
100
100
  det_model_backend (str): 'pytorch', or 'onnx'。表明检测时是使用 PyTorch 版本模型,还是使用 ONNX 版本模型。
@@ -110,13 +110,13 @@ class CnOcr(object):
110
110
  >>> ocr = CnOcr()
111
111
 
112
112
  使用指定模型:
113
- >>> ocr = CnOcr('densenet_lite_136-fc')
113
+ >>> ocr = CnOcr('densenet_lite_136-gru')
114
114
 
115
115
  识别时只考虑数字:
116
- >>> ocr = CnOcr(rec_model_name='densenet_lite_136-fc', det_model_name='naive_det', cand_alphabet='0123456789')
116
+ >>> ocr = CnOcr(rec_model_name='densenet_lite_136-gru', det_model_name='naive_det', cand_alphabet='0123456789')
117
117
 
118
118
  只检测和识别水平文字:
119
- >>> ocr = CnOcr(rec_model_name='densenet_lite_136-fc', det_model_name='db_shufflenet_v2_small', det_more_configs={'rotated_bbox': False})
119
+ >>> ocr = CnOcr(rec_model_name='densenet_lite_136-gru', det_model_name='db_shufflenet_v2_small', det_more_configs={'rotated_bbox': False})
120
120
 
121
121
  """
122
122
  if kwargs.get('model_name') is not None and rec_model_name is None: