cnocr 2.3.0.3__tar.gz → 2.3.2__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.
- {cnocr-2.3.0.3 → cnocr-2.3.2}/PKG-INFO +36 -8
- {cnocr-2.3.0.3 → cnocr-2.3.2}/README.md +35 -7
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/__version__.py +1 -1
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/app.py +1 -1
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/cli.py +2 -2
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/cn_ocr.py +5 -4
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/consts.py +12 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/data_utils/transforms.py +12 -13
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/dataset_utils.py +22 -12
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/gradio_app.py +1 -1
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/ppocr/__init__.py +1 -0
- cnocr-2.3.2/cnocr/ppocr/consts.py +86 -0
- cnocr-2.3.2/cnocr/ppocr/rapid_recognizer.py +206 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/ppocr/utility.py +17 -5
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/utils.py +11 -10
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr.egg-info/PKG-INFO +36 -8
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr.egg-info/SOURCES.txt +1 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr.egg-info/requires.txt +2 -1
- {cnocr-2.3.0.3 → cnocr-2.3.2}/setup.py +2 -1
- cnocr-2.3.0.3/cnocr/ppocr/consts.py +0 -48
- {cnocr-2.3.0.3 → cnocr-2.3.2}/LICENSE +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/__init__.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/classification/__init__.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/classification/dataset.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/classification/image_classifier.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/clf_cli.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/data_utils/__init__.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/data_utils/aug.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/data_utils/block_shuffle.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/data_utils/utils.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/dataset.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/gradio_app2.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/label_cn.txt +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/label_number.txt +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/line_split.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/lr_scheduler.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/models/__init__.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/models/ctc.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/models/densenet.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/models/mobilenet.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/models/ocr_model.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/ppocr/postprocess/__init__.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/ppocr/postprocess/rec_postprocess.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/ppocr/pp_recognizer.py +1 -1
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/ppocr/utils/__init__.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/ppocr/utils/chinese_cht_dict.txt +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/ppocr/utils/en_dict.txt +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/ppocr/utils/ppocr_keys_v1.txt +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/recognizer.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/serve.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr/trainer.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr.egg-info/dependency_links.txt +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr.egg-info/entry_points.txt +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr.egg-info/not-zip-safe +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/cnocr.egg-info/top_level.txt +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/setup.cfg +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/tests/test_cnocr.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/tests/test_dataset.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/tests/test_models.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/tests/test_ppocr.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/tests/test_pytorch.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/tests/test_trainer.py +0 -0
- {cnocr-2.3.0.3 → cnocr-2.3.2}/tests/test_transforms.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cnocr
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.2
|
|
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,24 @@ License-File: LICENSE
|
|
|
69
69
|
---
|
|
70
70
|
</div>
|
|
71
71
|
|
|
72
|
+
### Update 2025.06.26:发布 V2.3.2
|
|
73
|
+
|
|
74
|
+
主要变更:
|
|
75
|
+
|
|
76
|
+
* 集成 PPOCRv5 最新版 OCR 模型
|
|
77
|
+
* 新增支持 PP-OCRv5 识别模型:`ch_PP-OCRv5` 和 `ch_PP-OCRv5_server`
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
### [Update 2024.11.30]:发布 V2.3.1
|
|
81
|
+
|
|
82
|
+
主要变更:
|
|
83
|
+
|
|
84
|
+
* 基于 RapidOCR 集成 PPOCRv4 最新版 OCR 模型,提供更多的模型选择
|
|
85
|
+
* 新增支持 PP-OCRv4 识别模型,包括标准版和服务器版
|
|
86
|
+
* 修改读文件实现方式,支持 Windows 的中文路径
|
|
87
|
+
* 修复Bug:当使用多个进程时,transform_func 无法序列化
|
|
88
|
+
* 修复Bug:与 albumentations=1.4.* 兼容
|
|
89
|
+
|
|
72
90
|
### [Update 2023.12.24]:发布 V2.3
|
|
73
91
|
|
|
74
92
|
主要变更:
|
|
@@ -406,13 +424,15 @@ print(ocr_out)
|
|
|
406
424
|
| ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ------------------------------ | -------------------- |
|
|
407
425
|
| db_shufflenet_v2 | √ | X | cnocr | 18 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
408
426
|
| **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
427
|
| db_mobilenet_v3 | √ | X | cnocr | 16 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
411
428
|
| db_mobilenet_v3_small | √ | X | cnocr | 7.9 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
412
429
|
| db_resnet34 | √ | X | cnocr | 86 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
413
430
|
| db_resnet18 | √ | X | cnocr | 47 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
431
|
+
| ch_PP-OCRv5_det | X | √ | ppocr | 4.6 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
432
|
+
| ch_PP-OCRv5_det_server | X | √ | ppocr | 84 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
433
|
+
| ch_PP-OCRv4_det | X | √ | ppocr | 4.5 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
434
|
+
| ch_PP-OCRv4_det_server | X | √ | ppocr | 108 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
414
435
|
| ch_PP-OCRv3_det | X | √ | ppocr | 2.3 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
415
|
-
| ch_PP-OCRv2_det | X | √ | ppocr | 2.2 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
416
436
|
| **en_PP-OCRv3_det** | X | √ | ppocr | 2.3 M | **英文**、数字 | √ |
|
|
417
437
|
|
|
418
438
|
|
|
@@ -443,17 +463,26 @@ print(ocr_out)
|
|
|
443
463
|
| **densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
|
|
444
464
|
| **scene-densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
|
|
445
465
|
| **doc-densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
|
|
446
|
-
| **densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
447
|
-
| **scene-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
448
|
-
| **doc-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
466
|
+
| **densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11884138&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
|
|
467
|
+
| **scene-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11883935&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
|
|
468
|
+
| **doc-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11883965&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
|
|
449
469
|
| **number-densenet_lite_136-fc** 🆕 | √ | √ | cnocr | 2.7 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
|
|
450
470
|
| **number-densenet_lite_136-gru** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 5.5 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
|
|
451
|
-
| **number-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
471
|
+
| **number-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11884155&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 55 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
|
|
472
|
+
| ch_PP-OCRv5 | X | √ | ppocr | 16 M | 简体中文、英文、数字 | √ |
|
|
473
|
+
| ch_PP-OCRv5_server | X | √ | ppocr | 81 M | 简体中文、英文、数字 | √ |
|
|
474
|
+
| ch_PP-OCRv4 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
|
|
475
|
+
| ch_PP-OCRv4_server | X | √ | ppocr | 86 M | 简体中文、英文、数字 | √ |
|
|
452
476
|
| ch_PP-OCRv3 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
|
|
453
477
|
| ch_ppocr_mobile_v2.0 | X | √ | ppocr | 4.2 M | 简体中文、英文、数字 | √ |
|
|
478
|
+
| en_PP-OCRv4 | X | √ | ppocr | 8.6 M | **英文**、数字 | √ |
|
|
454
479
|
| en_PP-OCRv3 | X | √ | ppocr | 8.5 M | **英文**、数字 | √ |
|
|
455
480
|
| en_number_mobile_v2.0 | X | √ | ppocr | 1.8 M | **英文**、数字 | √ |
|
|
456
481
|
| chinese_cht_PP-OCRv3 | X | √ | ppocr | 11 M | **繁体中文**、英文、数字 | X |
|
|
482
|
+
| japan_PP-OCRv3 | X | √ | ppocr | 9.6 M | **日文**、英文、数字 | √ |
|
|
483
|
+
| korean_PP-OCRv3 | X | √ | ppocr | 9.4 M | **韩文**、英文、数字 | √ |
|
|
484
|
+
| latin_PP-OCRv3 | X | √ | ppocr | 8.6 M | **拉丁文**、英文、数字 | √ |
|
|
485
|
+
| arabic_PP-OCRv3 | X | √ | ppocr | 8.6 M | **阿拉伯文**、英文、数字 | √ |
|
|
457
486
|
|
|
458
487
|
|
|
459
488
|
|
|
@@ -484,4 +513,3 @@ print(ocr_out)
|
|
|
484
513
|
官方代码库:[https://github.com/breezedeus/cnocr](https://github.com/breezedeus/cnocr)。
|
|
485
514
|
|
|
486
515
|
|
|
487
|
-
|
|
@@ -39,6 +39,24 @@
|
|
|
39
39
|
---
|
|
40
40
|
</div>
|
|
41
41
|
|
|
42
|
+
### Update 2025.06.26:发布 V2.3.2
|
|
43
|
+
|
|
44
|
+
主要变更:
|
|
45
|
+
|
|
46
|
+
* 集成 PPOCRv5 最新版 OCR 模型
|
|
47
|
+
* 新增支持 PP-OCRv5 识别模型:`ch_PP-OCRv5` 和 `ch_PP-OCRv5_server`
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### [Update 2024.11.30]:发布 V2.3.1
|
|
51
|
+
|
|
52
|
+
主要变更:
|
|
53
|
+
|
|
54
|
+
* 基于 RapidOCR 集成 PPOCRv4 最新版 OCR 模型,提供更多的模型选择
|
|
55
|
+
* 新增支持 PP-OCRv4 识别模型,包括标准版和服务器版
|
|
56
|
+
* 修改读文件实现方式,支持 Windows 的中文路径
|
|
57
|
+
* 修复Bug:当使用多个进程时,transform_func 无法序列化
|
|
58
|
+
* 修复Bug:与 albumentations=1.4.* 兼容
|
|
59
|
+
|
|
42
60
|
### [Update 2023.12.24]:发布 V2.3
|
|
43
61
|
|
|
44
62
|
主要变更:
|
|
@@ -376,13 +394,15 @@ print(ocr_out)
|
|
|
376
394
|
| ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ------------------------------ | -------------------- |
|
|
377
395
|
| db_shufflenet_v2 | √ | X | cnocr | 18 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
378
396
|
| **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
397
|
| db_mobilenet_v3 | √ | X | cnocr | 16 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
381
398
|
| db_mobilenet_v3_small | √ | X | cnocr | 7.9 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
382
399
|
| db_resnet34 | √ | X | cnocr | 86 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
383
400
|
| db_resnet18 | √ | X | cnocr | 47 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
401
|
+
| ch_PP-OCRv5_det | X | √ | ppocr | 4.6 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
402
|
+
| ch_PP-OCRv5_det_server | X | √ | ppocr | 84 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
403
|
+
| ch_PP-OCRv4_det | X | √ | ppocr | 4.5 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
404
|
+
| ch_PP-OCRv4_det_server | X | √ | ppocr | 108 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
384
405
|
| ch_PP-OCRv3_det | X | √ | ppocr | 2.3 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
385
|
-
| ch_PP-OCRv2_det | X | √ | ppocr | 2.2 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
386
406
|
| **en_PP-OCRv3_det** | X | √ | ppocr | 2.3 M | **英文**、数字 | √ |
|
|
387
407
|
|
|
388
408
|
|
|
@@ -413,17 +433,26 @@ print(ocr_out)
|
|
|
413
433
|
| **densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
|
|
414
434
|
| **scene-densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
|
|
415
435
|
| **doc-densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
|
|
416
|
-
| **densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
417
|
-
| **scene-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
418
|
-
| **doc-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
436
|
+
| **densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11884138&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
|
|
437
|
+
| **scene-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11883935&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
|
|
438
|
+
| **doc-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11883965&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
|
|
419
439
|
| **number-densenet_lite_136-fc** 🆕 | √ | √ | cnocr | 2.7 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
|
|
420
440
|
| **number-densenet_lite_136-gru** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 5.5 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
|
|
421
|
-
| **number-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
441
|
+
| **number-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11884155&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 55 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
|
|
442
|
+
| ch_PP-OCRv5 | X | √ | ppocr | 16 M | 简体中文、英文、数字 | √ |
|
|
443
|
+
| ch_PP-OCRv5_server | X | √ | ppocr | 81 M | 简体中文、英文、数字 | √ |
|
|
444
|
+
| ch_PP-OCRv4 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
|
|
445
|
+
| ch_PP-OCRv4_server | X | √ | ppocr | 86 M | 简体中文、英文、数字 | √ |
|
|
422
446
|
| ch_PP-OCRv3 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
|
|
423
447
|
| ch_ppocr_mobile_v2.0 | X | √ | ppocr | 4.2 M | 简体中文、英文、数字 | √ |
|
|
448
|
+
| en_PP-OCRv4 | X | √ | ppocr | 8.6 M | **英文**、数字 | √ |
|
|
424
449
|
| en_PP-OCRv3 | X | √ | ppocr | 8.5 M | **英文**、数字 | √ |
|
|
425
450
|
| en_number_mobile_v2.0 | X | √ | ppocr | 1.8 M | **英文**、数字 | √ |
|
|
426
451
|
| chinese_cht_PP-OCRv3 | X | √ | ppocr | 11 M | **繁体中文**、英文、数字 | X |
|
|
452
|
+
| japan_PP-OCRv3 | X | √ | ppocr | 9.6 M | **日文**、英文、数字 | √ |
|
|
453
|
+
| korean_PP-OCRv3 | X | √ | ppocr | 9.4 M | **韩文**、英文、数字 | √ |
|
|
454
|
+
| latin_PP-OCRv3 | X | √ | ppocr | 8.6 M | **拉丁文**、英文、数字 | √ |
|
|
455
|
+
| arabic_PP-OCRv3 | X | √ | ppocr | 8.6 M | **阿拉伯文**、英文、数字 | √ |
|
|
427
456
|
|
|
428
457
|
|
|
429
458
|
|
|
@@ -452,4 +481,3 @@ print(ocr_out)
|
|
|
452
481
|
---
|
|
453
482
|
|
|
454
483
|
官方代码库:[https://github.com/breezedeus/cnocr](https://github.com/breezedeus/cnocr)。
|
|
455
|
-
|
|
@@ -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-
|
|
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-
|
|
219
|
-
help='检测模型名称。默认值为 ch_PP-
|
|
218
|
+
default='ch_PP-OCRv5_det',
|
|
219
|
+
help='检测模型名称。默认值为 ch_PP-OCRv5_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-
|
|
67
|
+
det_model_name: str = 'ch_PP-OCRv5_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-
|
|
86
|
+
det_model_name (str): 检测模型名称。默认为 `ch_PP-OCRv5_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
|
-
|
|
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(
|
|
141
|
+
class RandomStretchAug(ImageOnlyTransform):
|
|
142
142
|
"""保持高度不变的情况下,对图像的宽度进行随机拉伸"""
|
|
143
|
+
|
|
143
144
|
def __init__(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
super(
|
|
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(
|
|
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(
|
|
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-
|
|
175
|
+
label='选择检测模型', choices=det_models, value='ch_PP-OCRv4_det::onnx',
|
|
176
176
|
)
|
|
177
177
|
|
|
178
178
|
rec_model_name = gr.Dropdown(
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
("ch_PP-OCRv5", "onnx"): {
|
|
77
|
+
"recognizer": "RapidRecognizer",
|
|
78
|
+
"repo": "breezedeus/cnocr-ppocr-ch_PP-OCRv5",
|
|
79
|
+
},
|
|
80
|
+
("ch_PP-OCRv5_server", "onnx"): {
|
|
81
|
+
"recognizer": "RapidRecognizer",
|
|
82
|
+
"repo": "breezedeus/cnocr-ppocr-ch_PP-OCRv5_server",
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
PP_SPACE = "ppocr"
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
# Copyright (C) 2022-2025, [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 import EngineType, LangRec, ModelType, OCRVersion
|
|
13
|
+
from rapidocr.utils.typings import TaskType
|
|
14
|
+
from rapidocr.ch_ppocr_rec import TextRecognizer, TextRecInput
|
|
15
|
+
from cnstd.utils import prepare_model_files
|
|
16
|
+
|
|
17
|
+
from ..utils import data_dir, read_img
|
|
18
|
+
from ..recognizer import Recognizer
|
|
19
|
+
from .consts import PP_SPACE
|
|
20
|
+
from ..consts import MODEL_VERSION, AVAILABLE_MODELS
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Config(dict):
|
|
27
|
+
DEFAULT_CFG = {
|
|
28
|
+
"engine_type": EngineType.ONNXRUNTIME,
|
|
29
|
+
"lang_type": LangRec.CH,
|
|
30
|
+
"model_type": ModelType.MOBILE,
|
|
31
|
+
"ocr_version": OCRVersion.PPOCRV5,
|
|
32
|
+
"task_type": TaskType.REC,
|
|
33
|
+
"model_path": None,
|
|
34
|
+
"model_dir": None,
|
|
35
|
+
"rec_keys_path": None,
|
|
36
|
+
"rec_img_shape": [3, 48, 320],
|
|
37
|
+
"rec_batch_num": 6,
|
|
38
|
+
"engine_cfg": {
|
|
39
|
+
"intra_op_num_threads": -1,
|
|
40
|
+
"inter_op_num_threads": -1,
|
|
41
|
+
"enable_cpu_mem_arena": False,
|
|
42
|
+
"cpu_ep_cfg": {"arena_extend_strategy": "kSameAsRequested"},
|
|
43
|
+
"use_cuda": False,
|
|
44
|
+
"cuda_ep_cfg": {
|
|
45
|
+
"device_id": 0,
|
|
46
|
+
"arena_extend_strategy": "kNextPowerOfTwo",
|
|
47
|
+
"cudnn_conv_algo_search": "EXHAUSTIVE",
|
|
48
|
+
"do_copy_in_default_stream": True,
|
|
49
|
+
},
|
|
50
|
+
"use_dml": False,
|
|
51
|
+
"dm_ep_cfg": None,
|
|
52
|
+
"use_cann": False,
|
|
53
|
+
"cann_ep_cfg": {
|
|
54
|
+
"device_id": 0,
|
|
55
|
+
"arena_extend_strategy": "kNextPowerOfTwo",
|
|
56
|
+
"npu_mem_limit": 21474836480,
|
|
57
|
+
"op_select_impl_mode": "high_performance",
|
|
58
|
+
"optypelist_for_implmode": "Gelu",
|
|
59
|
+
"enable_cann_graph": True,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
def __init__(self, *args, **kwargs):
|
|
65
|
+
super().__init__()
|
|
66
|
+
data = dict(*args, **kwargs)
|
|
67
|
+
for k, v in data.items():
|
|
68
|
+
if isinstance(v, dict):
|
|
69
|
+
v = Config(v)
|
|
70
|
+
self[k] = v
|
|
71
|
+
|
|
72
|
+
def __getattr__(self, name):
|
|
73
|
+
try:
|
|
74
|
+
return self[name]
|
|
75
|
+
except KeyError:
|
|
76
|
+
raise AttributeError(name)
|
|
77
|
+
|
|
78
|
+
def __setattr__(self, name, value):
|
|
79
|
+
self[name] = value
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class RapidRecognizer(Recognizer):
|
|
83
|
+
def __init__(
|
|
84
|
+
self,
|
|
85
|
+
model_name: str = "ch_PP-OCRv5",
|
|
86
|
+
*,
|
|
87
|
+
model_fp: Optional[str] = None,
|
|
88
|
+
root: Union[str, Path] = data_dir(),
|
|
89
|
+
context: str = "cpu", # ['cpu', 'gpu']
|
|
90
|
+
rec_image_shape: str = "3, 48, 320",
|
|
91
|
+
**kwargs
|
|
92
|
+
):
|
|
93
|
+
"""
|
|
94
|
+
基于 rapidocr_onnxruntime 的文本识别器。
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
model_name (str): 模型名称。默认为 `ch_PP-OCRv5`
|
|
98
|
+
model_fp (Optional[str]): 如果不使用系统自带的模型,可以通过此参数直接指定所使用的模型文件('.onnx' 文件)
|
|
99
|
+
root (Union[str, Path]): 模型文件所在的根目录
|
|
100
|
+
context (str): 使用的设备。默认为 `cpu`,可选 `gpu`
|
|
101
|
+
rec_image_shape (str): 输入图片尺寸,无需更改使用默认值即可。默认值:`"3, 48, 320"`
|
|
102
|
+
**kwargs: 其他参数
|
|
103
|
+
"""
|
|
104
|
+
self.rec_image_shape = [int(v) for v in rec_image_shape.split(",")]
|
|
105
|
+
self._model_name = model_name
|
|
106
|
+
self._model_backend = "onnx"
|
|
107
|
+
use_gpu = context.lower() not in ("cpu", "mps")
|
|
108
|
+
|
|
109
|
+
self._assert_and_prepare_model_files(model_fp, root)
|
|
110
|
+
|
|
111
|
+
config = Config.DEFAULT_CFG
|
|
112
|
+
config["engine_cfg"]["use_cuda"] = use_gpu
|
|
113
|
+
if "engine_cfg" in kwargs:
|
|
114
|
+
config["engine_cfg"].update(kwargs["engine_cfg"])
|
|
115
|
+
config["rec_img_shape"] = self.rec_image_shape
|
|
116
|
+
config["model_path"] = self._model_fp
|
|
117
|
+
# 从 model_name 中获取 model_type 和 ocr_version
|
|
118
|
+
config["model_type"] = ModelType.SERVER if "server" in model_name else ModelType.MOBILE
|
|
119
|
+
config["ocr_version"] = OCRVersion.PPOCRV5 if "v5" in model_name else OCRVersion.PPOCRV4
|
|
120
|
+
|
|
121
|
+
config = Config(config)
|
|
122
|
+
self.recognizer = TextRecognizer(config)
|
|
123
|
+
|
|
124
|
+
def _assert_and_prepare_model_files(self, model_fp, root):
|
|
125
|
+
if model_fp is not None and not os.path.isfile(model_fp):
|
|
126
|
+
raise FileNotFoundError("can not find model file %s" % model_fp)
|
|
127
|
+
|
|
128
|
+
if model_fp is not None:
|
|
129
|
+
self._model_fp = model_fp
|
|
130
|
+
return
|
|
131
|
+
|
|
132
|
+
root = os.path.join(root, MODEL_VERSION)
|
|
133
|
+
self._model_dir = os.path.join(root, PP_SPACE, self._model_name)
|
|
134
|
+
model_fp = os.path.join(self._model_dir, "%s_rec_infer.onnx" % self._model_name)
|
|
135
|
+
if not os.path.isfile(model_fp):
|
|
136
|
+
logger.warning("can not find model file %s" % model_fp)
|
|
137
|
+
if (self._model_name, self._model_backend) not in AVAILABLE_MODELS:
|
|
138
|
+
raise NotImplementedError(
|
|
139
|
+
"%s is not a downloadable model"
|
|
140
|
+
% ((self._model_name, self._model_backend),)
|
|
141
|
+
)
|
|
142
|
+
remote_repo = AVAILABLE_MODELS.get_value(
|
|
143
|
+
self._model_name, self._model_backend, "repo"
|
|
144
|
+
)
|
|
145
|
+
model_fp = prepare_model_files(model_fp, remote_repo)
|
|
146
|
+
|
|
147
|
+
self._model_fp = model_fp
|
|
148
|
+
logger.info("use model: %s" % self._model_fp)
|
|
149
|
+
|
|
150
|
+
def recognize(
|
|
151
|
+
self,
|
|
152
|
+
img_list: List[Union[str, Path, np.ndarray]],
|
|
153
|
+
batch_size: int = 6,
|
|
154
|
+
return_word_box: bool = False,
|
|
155
|
+
) -> List[Tuple[str, float]]:
|
|
156
|
+
"""
|
|
157
|
+
识别图片中的文字。
|
|
158
|
+
Args:
|
|
159
|
+
img_list: 支持以下格式的图片数据:
|
|
160
|
+
+ 图片路径
|
|
161
|
+
+ 已经从图片文件中读入的数据
|
|
162
|
+
batch_size: 待处理图片数据的批大小。
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
列表,每个元素是对应图片的识别结果,由 (text, score) 组成,其中:
|
|
166
|
+
+ text: 识别出的文本
|
|
167
|
+
+ score: 识别结果的得分
|
|
168
|
+
"""
|
|
169
|
+
if not isinstance(img_list, (list, tuple)):
|
|
170
|
+
img_list = [img_list]
|
|
171
|
+
|
|
172
|
+
self.recognizer.rec_batch_num = batch_size
|
|
173
|
+
|
|
174
|
+
img_data_list = []
|
|
175
|
+
for img in img_list:
|
|
176
|
+
if isinstance(img, (str, Path)):
|
|
177
|
+
img = read_img(img, gray=False)
|
|
178
|
+
if len(img.shape) == 3 and img.shape[2] == 3:
|
|
179
|
+
img = img[..., ::-1] # RGB to BGR
|
|
180
|
+
img_data_list.append(img)
|
|
181
|
+
|
|
182
|
+
rec_input = TextRecInput(img=img_data_list, return_word_box=return_word_box)
|
|
183
|
+
try:
|
|
184
|
+
results = self.recognizer(rec_input)
|
|
185
|
+
return [(txt, score) for txt, score in zip(results.txts, results.scores)]
|
|
186
|
+
except Exception as e:
|
|
187
|
+
logger.error(f"Error recognizing image: {e}")
|
|
188
|
+
return []
|
|
189
|
+
|
|
190
|
+
def recognize_one_line(
|
|
191
|
+
self, img: Union[str, Path, np.ndarray]
|
|
192
|
+
) -> Tuple[str, float]:
|
|
193
|
+
"""
|
|
194
|
+
识别图片中的一行文字。
|
|
195
|
+
Args:
|
|
196
|
+
img: 支持以下格式的图片数据:
|
|
197
|
+
+ 图片路径
|
|
198
|
+
+ 已经从图片文件中读入的数据
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
(text, score):
|
|
202
|
+
+ text: 识别出的文本
|
|
203
|
+
+ score: 识别结果的得分
|
|
204
|
+
"""
|
|
205
|
+
results = self.recognize([img])
|
|
206
|
+
return results[0]
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
import argparse
|
|
22
22
|
import os
|
|
23
23
|
import sys
|
|
24
|
-
import imghdr
|
|
25
24
|
import math
|
|
26
25
|
import logging
|
|
27
26
|
|
|
@@ -510,15 +509,28 @@ def get_image_file_list(img_file):
|
|
|
510
509
|
raise Exception("not found any img file in {}".format(img_file))
|
|
511
510
|
|
|
512
511
|
img_end = {'jpg', 'bmp', 'png', 'jpeg', 'rgb', 'tif', 'tiff', 'gif', 'GIF'}
|
|
513
|
-
|
|
514
|
-
|
|
512
|
+
|
|
513
|
+
if os.path.isfile(img_file):
|
|
514
|
+
try:
|
|
515
|
+
with Image.open(img_file) as img:
|
|
516
|
+
if img.format and img.format.lower() in [ext.lower() for ext in img_end]:
|
|
517
|
+
imgs_lists.append(img_file)
|
|
518
|
+
except Exception:
|
|
519
|
+
pass
|
|
515
520
|
elif os.path.isdir(img_file):
|
|
516
521
|
for single_file in os.listdir(img_file):
|
|
517
522
|
file_path = os.path.join(img_file, single_file)
|
|
518
|
-
if os.path.isfile(file_path)
|
|
519
|
-
|
|
523
|
+
if os.path.isfile(file_path):
|
|
524
|
+
try:
|
|
525
|
+
with Image.open(file_path) as img:
|
|
526
|
+
if img.format and img.format.lower() in [ext.lower() for ext in img_end]:
|
|
527
|
+
imgs_lists.append(file_path)
|
|
528
|
+
except Exception:
|
|
529
|
+
pass
|
|
530
|
+
|
|
520
531
|
if len(imgs_lists) == 0:
|
|
521
532
|
raise Exception("not found any img file in {}".format(img_file))
|
|
533
|
+
|
|
522
534
|
imgs_lists = sorted(imgs_lists)
|
|
523
535
|
return imgs_lists
|
|
524
536
|
|
|
@@ -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 =
|
|
277
|
-
|
|
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 =
|
|
282
|
-
|
|
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.
|
|
3
|
+
Version: 2.3.2
|
|
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,24 @@ License-File: LICENSE
|
|
|
69
69
|
---
|
|
70
70
|
</div>
|
|
71
71
|
|
|
72
|
+
### Update 2025.06.26:发布 V2.3.2
|
|
73
|
+
|
|
74
|
+
主要变更:
|
|
75
|
+
|
|
76
|
+
* 集成 PPOCRv5 最新版 OCR 模型
|
|
77
|
+
* 新增支持 PP-OCRv5 识别模型:`ch_PP-OCRv5` 和 `ch_PP-OCRv5_server`
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
### [Update 2024.11.30]:发布 V2.3.1
|
|
81
|
+
|
|
82
|
+
主要变更:
|
|
83
|
+
|
|
84
|
+
* 基于 RapidOCR 集成 PPOCRv4 最新版 OCR 模型,提供更多的模型选择
|
|
85
|
+
* 新增支持 PP-OCRv4 识别模型,包括标准版和服务器版
|
|
86
|
+
* 修改读文件实现方式,支持 Windows 的中文路径
|
|
87
|
+
* 修复Bug:当使用多个进程时,transform_func 无法序列化
|
|
88
|
+
* 修复Bug:与 albumentations=1.4.* 兼容
|
|
89
|
+
|
|
72
90
|
### [Update 2023.12.24]:发布 V2.3
|
|
73
91
|
|
|
74
92
|
主要变更:
|
|
@@ -406,13 +424,15 @@ print(ocr_out)
|
|
|
406
424
|
| ------------------------------------------------------------ | ------------ | --------- | ------------ | ------------ | ------------------------------ | -------------------- |
|
|
407
425
|
| db_shufflenet_v2 | √ | X | cnocr | 18 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
408
426
|
| **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
427
|
| db_mobilenet_v3 | √ | X | cnocr | 16 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
411
428
|
| db_mobilenet_v3_small | √ | X | cnocr | 7.9 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
412
429
|
| db_resnet34 | √ | X | cnocr | 86 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
413
430
|
| db_resnet18 | √ | X | cnocr | 47 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
431
|
+
| ch_PP-OCRv5_det | X | √ | ppocr | 4.6 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
432
|
+
| ch_PP-OCRv5_det_server | X | √ | ppocr | 84 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
433
|
+
| ch_PP-OCRv4_det | X | √ | ppocr | 4.5 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
434
|
+
| ch_PP-OCRv4_det_server | X | √ | ppocr | 108 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
414
435
|
| ch_PP-OCRv3_det | X | √ | ppocr | 2.3 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
415
|
-
| ch_PP-OCRv2_det | X | √ | ppocr | 2.2 M | 简体中文、繁体中文、英文、数字 | √ |
|
|
416
436
|
| **en_PP-OCRv3_det** | X | √ | ppocr | 2.3 M | **英文**、数字 | √ |
|
|
417
437
|
|
|
418
438
|
|
|
@@ -443,17 +463,26 @@ print(ocr_out)
|
|
|
443
463
|
| **densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
|
|
444
464
|
| **scene-densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
|
|
445
465
|
| **doc-densenet_lite_246-gru_base** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 25 M | 简体中文、英文、数字 | X |
|
|
446
|
-
| **densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
447
|
-
| **scene-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
448
|
-
| **doc-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
466
|
+
| **densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11884138&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
|
|
467
|
+
| **scene-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11883935&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
|
|
468
|
+
| **doc-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11883965&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 82 M | 简体中文、英文、数字 | X |
|
|
449
469
|
| **number-densenet_lite_136-fc** 🆕 | √ | √ | cnocr | 2.7 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
|
|
450
470
|
| **number-densenet_lite_136-gru** 🆕 <br /> ([星球会员](https://t.zsxq.com/FEYZRJQ)专享) | √ | √ | cnocr | 5.5 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
|
|
451
|
-
| **number-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://
|
|
471
|
+
| **number-densenet_lite_666-gru_large** 🆕 <br />(购买链接:[B站](https://mall.bilibili.com/neul-next/detailuniversal/detail.html?isMerchant=1&page=detailuniversal_detail&saleType=10&itemsId=11884155&loadingShow=1&noTitleBar=1&msource=merchant_share)、[Lemon Squeezy](https://ocr.lemonsqueezy.com/)) | √ | √ | cnocr | 55 M | **纯数字**(仅包含 `0~9` 十个数字) | X |
|
|
472
|
+
| ch_PP-OCRv5 | X | √ | ppocr | 16 M | 简体中文、英文、数字 | √ |
|
|
473
|
+
| ch_PP-OCRv5_server | X | √ | ppocr | 81 M | 简体中文、英文、数字 | √ |
|
|
474
|
+
| ch_PP-OCRv4 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
|
|
475
|
+
| ch_PP-OCRv4_server | X | √ | ppocr | 86 M | 简体中文、英文、数字 | √ |
|
|
452
476
|
| ch_PP-OCRv3 | X | √ | ppocr | 10 M | 简体中文、英文、数字 | √ |
|
|
453
477
|
| ch_ppocr_mobile_v2.0 | X | √ | ppocr | 4.2 M | 简体中文、英文、数字 | √ |
|
|
478
|
+
| en_PP-OCRv4 | X | √ | ppocr | 8.6 M | **英文**、数字 | √ |
|
|
454
479
|
| en_PP-OCRv3 | X | √ | ppocr | 8.5 M | **英文**、数字 | √ |
|
|
455
480
|
| en_number_mobile_v2.0 | X | √ | ppocr | 1.8 M | **英文**、数字 | √ |
|
|
456
481
|
| chinese_cht_PP-OCRv3 | X | √ | ppocr | 11 M | **繁体中文**、英文、数字 | X |
|
|
482
|
+
| japan_PP-OCRv3 | X | √ | ppocr | 9.6 M | **日文**、英文、数字 | √ |
|
|
483
|
+
| korean_PP-OCRv3 | X | √ | ppocr | 9.4 M | **韩文**、英文、数字 | √ |
|
|
484
|
+
| latin_PP-OCRv3 | X | √ | ppocr | 8.6 M | **拉丁文**、英文、数字 | √ |
|
|
485
|
+
| arabic_PP-OCRv3 | X | √ | ppocr | 8.6 M | **阿拉伯文**、英文、数字 | √ |
|
|
457
486
|
|
|
458
487
|
|
|
459
488
|
|
|
@@ -484,4 +513,3 @@ print(ocr_out)
|
|
|
484
513
|
官方代码库:[https://github.com/breezedeus/cnocr](https://github.com/breezedeus/cnocr)。
|
|
485
514
|
|
|
486
515
|
|
|
487
|
-
|
|
@@ -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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|