Skip to content

📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.

Update README

SWHL08022053c548
diff --git a/README.md b/README.md
index 7dc2a1e..7b75843 100755
--- a/README.md
+++ b/README.md
@@ -13,11 +13,12 @@
- [RapidOCR (捷智OCR)](#rapidocr-捷智ocr)
- [简介](#简介)
- [近期更新](#近期更新)
- - [🎃2021-10-27 update](#2021-10-27-update)
+ - [✨2021-11-13 update](#2021-11-13-update)
+ - [2021-10-27 update](#2021-10-27-update)
- [2021-09-13 update](#2021-09-13-update)
- [2021-09-11 update](#2021-09-11-update)
- - [2021-08-07 update](#2021-08-07-update)
- [之前更新记录](#之前更新记录)
+ - [2021-08-07 update](#2021-08-07-update)
- [2021-07-17 update](#2021-07-17-update)
- [2021-07-04 update](#2021-07-04-update)
- [2021-06-20 update](#2021-06-20-update)
@@ -54,7 +55,11 @@
- 基于百度的开源PaddleOCR 模型及训练,任何人可以使用本推理库,也可以根据自己的需求使用百度的paddlepaddle框架进行模型优化。
## 近期更新
-#### 🎃2021-10-27 update
+#### ✨2021-11-13 update
+- 添加python版本中文本检测和识别可调节的超参数,主要有`box_thresh|unclip_ratio|text_score`,详情见[参数调节](python/README.md#相关调节参数)
+- 将文本识别中字典位置以参数方式给出,便于灵活配置,详情见[keys_path](python/rapidOCR.sh)
+
+#### 2021-10-27 update
- 添加使用onnxruntime-gpu版推理的代码(不过gpu版本的onnxruntime不太好用,按照[官方教程](https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html)配置,感觉没有调用起来GPU)
- 具体使用步骤参见: [onnxruntime-gpu推理配置](python/README.md)
@@ -69,6 +74,10 @@
- PP-OCRv2识别模型效果无明显提升,模型大小增加了3.58M。
- 模型上传到[百度网盘 提取码:30jv](https://pan.baidu.com/s/1qkqWK4wRdMjqGGbzR-FyWg)
+#### 之前更新记录
+<details>
+ <summary>点击查看</summary>
+
#### 2021-08-07 update
- 现在正在做的
- [ ] PP-Structure 表格结构和cell坐标预测 正在整理中
@@ -77,10 +86,6 @@
- [ ] 打Dokcer镜像
- [x] 尝试onnxruntime-gpu推理
-#### 之前更新记录
-<details>
- <summary>点击查看</summary>
-
##### 2021-07-17 update
- 完善README文档
- 增加**英文、数字识别**onnx模型,具体参见`python/en_number_ppocr_mobile_v2_rec`,用法同其他
diff --git a/README_en.md b/README_en.md
index 1a9e570..b9245b4 100644
--- a/README_en.md
+++ b/README_en.md
@@ -12,11 +12,12 @@ English | [Chinese](README.md)
- [RapidOCR](#rapidocr)
- [Introduction](#introduction)
- [Recently updates](#recently-updates)
- - [🎃2021-10-27 update](#2021-10-27-update)
+ - [✨2021-11-13 update](#2021-11-13-update)
+ - [2021-10-27 update](#2021-10-27-update)
- [2021-09-13 update](#2021-09-13-update)
- [2021-09-11 update](#2021-09-11-update)
- - [2021-08-07 update](#2021-08-07-update)
- [Recently updates](#Recently-updates)
+ - [2021-08-07 update](#2021-08-07-update)
- [2021-07-17 update](#2021-07-17-update)
- [2021-07-04 update](#2021-07-04-update)
- [2021-06-20 update](#2021-06-20-update)
@@ -52,8 +53,11 @@ English | [Chinese](README.md)
- Based on Baidu's open source PaddleOCR model and training, anyone can use this inference library, or use Baidu's paddlepaddle framework for model optimization according to their own needs.
## Recently updates
+#### ✨2021-11-13 update
+- Add adjustable super parameters for text detection and recognition in Python version, mainly `box_thresh|unclip_ratio|text_score`, see [parameter adjustment](python/README.md#相关调节参数) for details
+- The dictionary position in text recognition is given in parameter mode to facilitate flexible configuration. See [keys_path](python/rapidOCR.sh) for details
-#### 🎃 2021-10-27 update
+#### 2021-10-27 update
- Add the code that uses the onnxruntime GPU version of infering follow the [official tutorial](https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html) Configuration. (however, the onnxruntime GPU version is not stable to use)
- See: `python/README.md` for specific steps.
@@ -70,6 +74,9 @@ English | [Chinese](README.md)
- Upload the model to [Baidu online disk extraction code: 30jv](https://pan.baidu.com/s/1qkqWK4wRdMjqGGbzR-FyWg) or [Google Drive](https://drive.google.com/drive/folders/1x_a9KpCo_1blxH1xFOfgKVkw1HYRVywY?usp=sharing)
+<details>
+ <summary>Previous update logs</summary>
+
#### 2021-08-07 update
- TODO:
- [ ] PP structure table structure and cell coordinate prediction are being sorted out.
@@ -78,10 +85,6 @@ English | [Chinese](README.md)
- [ ] make dokcer image
- [x] try onnxruntime GPU reasoning
-
-<details>
- <summary>Previous update logs</summary>
-
#### 2021-07-17 update
- Improve the README document
- Add **English, number recognition**onnx model, please refer to `python/en_number_ppocr_mobile_v2_rec` for details, the usage is the same as others
diff --git a/python/README.md b/python/README.md
index 15962de..426febb 100755
--- a/python/README.md
+++ b/python/README.md
@@ -21,21 +21,23 @@ cls_model_path = 'models/ch_ppocr_mobile_v2.0_cls_infer.onnx'
rec_model_path = 'models/ch_ppocr_mobile_v2.0_rec_infer.onnx'
image_path = r'test_images/det_images/1.jpg'
+keys_path = 'ch_ppocr_mobile_v2_rec/ppocr_keys_v1.txt'
text_sys = TextSystem(det_model_path,
- rec_model_path,
- use_angle_cls=True,
- cls_model_path=cls_model_path)
+ rec_model_path,
+ use_angle_cls=True,
+ cls_model_path=cls_model_path,
+ keys_path=keys_path)
dt_boxes, rec_res = text_sys(image_path)
visualize(image_path, dt_boxes, rec_res)
```
-#### 相关调节参数如下
+### 相关调节参数
|参数名称|作用|建议取值范围|默认值|代码位置|
|:---:|:---:|:---:|:---:|:---:|
-|box_thresh|文本检测所得框是否保留的阈值,值越大,召回率越低|[0, 1]|0.5||
-|unclip_ratio|控制文本检测框的大小,值越大,检测框整体越大|[1.6, 2.0]|1.6||
-|text_score|文本识别结果置信度,值越大,把握越大|[0, 1]|0.5||
+|box_thresh|文本检测所得框是否保留的阈值,值越大,召回率越低|[0, 1]|0.5|[text_detect.py](https://github.com/RapidAI/RapidOCR/blob/6aa79aa390c9c9e8f41df0f0c35f3dca97e6dc93/python/ch_ppocr_mobile_v2_det/text_detect.py?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L55)|
+|unclip_ratio|控制文本检测框的大小,值越大,检测框整体越大|[1.6, 2.0]|1.6|[text_detect.py](https://github.com/RapidAI/RapidOCR/blob/6aa79aa390c9c9e8f41df0f0c35f3dca97e6dc93/python/ch_ppocr_mobile_v2_det/text_detect.py?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L57)|
+|text_score|文本识别结果置信度,值越大,把握越大|[0, 1]|0.5|[rapidOCR.py](https://github.com/RapidAI/RapidOCR/blob/6aa79aa390c9c9e8f41df0f0c35f3dca97e6dc93/python/rapidOCR.py?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L270)|
### onnxruntime-gpu版推理配置
diff --git a/python/ch_ppocr_mobile_v2_rec/text_recognize.py b/python/ch_ppocr_mobile_v2_rec/text_recognize.py
index baeee61..d196148 100755
--- a/python/ch_ppocr_mobile_v2_rec/text_recognize.py
+++ b/python/ch_ppocr_mobile_v2_rec/text_recognize.py
@@ -30,11 +30,14 @@ root_path = Path(__file__).parent
class TextRecognizer(object):
- def __init__(self, rec_model_path):
+ def __init__(self, rec_model_path, keys_path=None):
self.rec_image_shape = [3, 32, 320]
self.rec_batch_num = 6
- self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')
+ if keys_path is not None:
+ self.character_dict_path = keys_path
+ else:
+ self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')
self.postprocess_op = CTCLabelDecode(self.character_dict_path)
sess_opt = onnxruntime.SessionOptions()
diff --git a/python/ch_ppocr_server_v2_rec/text_recognize.py b/python/ch_ppocr_server_v2_rec/text_recognize.py
index 894330f..9817882 100755
--- a/python/ch_ppocr_server_v2_rec/text_recognize.py
+++ b/python/ch_ppocr_server_v2_rec/text_recognize.py
@@ -30,11 +30,14 @@ root_path = Path(__file__).parent
class TextRecognizer(object):
- def __init__(self, rec_model_path):
+ def __init__(self, rec_model_path, keys_path=None):
self.rec_image_shape = [3, 32, 320]
self.rec_batch_num = 6
- self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')
+ if keys_path is not None:
+ self.character_dict_path = keys_path
+ else:
+ self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')
self.postprocess_op = CTCLabelDecode(self.character_dict_path)
sess_opt = onnxruntime.SessionOptions()
diff --git a/python/en_number_ppocr_mobile_v2_rec/text_recognize.py b/python/en_number_ppocr_mobile_v2_rec/text_recognize.py
index a6a1357..6af2413 100644
--- a/python/en_number_ppocr_mobile_v2_rec/text_recognize.py
+++ b/python/en_number_ppocr_mobile_v2_rec/text_recognize.py
@@ -30,11 +30,15 @@ root_path = Path(__file__).parent
class TextRecognizer(object):
- def __init__(self, rec_model_path):
+ def __init__(self, rec_model_path, keys_path=None):
self.rec_image_shape = [3, 32, 320]
self.rec_batch_num = 6
- self.character_dict_path = str(root_path / 'en_dict.txt')
+ if keys_path is not None:
+ self.character_dict_path = keys_path
+ else:
+ self.character_dict_path = str(root_path / 'en_dict.txt')
+
self.postprocess_op = CTCLabelDecode(self.character_dict_path)
sess_opt = onnxruntime.SessionOptions()
diff --git a/python/japan_ppocr_mobile_v2_rec/text_recognize.py b/python/japan_ppocr_mobile_v2_rec/text_recognize.py
index e7877aa..2409471 100644
--- a/python/japan_ppocr_mobile_v2_rec/text_recognize.py
+++ b/python/japan_ppocr_mobile_v2_rec/text_recognize.py
@@ -30,11 +30,15 @@ root_path = Path(__file__).parent
class TextRecognizer(object):
- def __init__(self, rec_model_path):
+ def __init__(self, rec_model_path, keys_path=None):
self.rec_image_shape = [3, 32, 320]
self.rec_batch_num = 6
- self.character_dict_path = str(root_path / 'japan_dict.txt')
+ if keys_path is not None:
+ self.character_dict_path = keys_path
+ else:
+ self.character_dict_path = str(root_path / 'japan_dict.txt')
+
self.postprocess_op = CTCLabelDecode(self.character_dict_path)
sess_opt = onnxruntime.SessionOptions()
diff --git a/python/rapidOCR.py b/python/rapidOCR.py
index f579cca..3c68571 100644
--- a/python/rapidOCR.py
+++ b/python/rapidOCR.py
@@ -148,10 +148,11 @@ class TextSystem(object):
def __init__(self, det_model_path,
rec_model_path,
use_angle_cls=False,
- cls_model_path=None) -> None:
+ cls_model_path=None,
+ keys_path=None):
super(TextSystem).__init__()
self.text_detector = TextDetector(det_model_path)
- self.text_recognizer = TextRecognizer(rec_model_path)
+ self.text_recognizer = TextRecognizer(rec_model_path, keys_path)
self.use_angle_cls = use_angle_cls
if self.use_angle_cls:
self.text_classifier = TextClassifier(cls_model_path)
@@ -266,6 +267,9 @@ if __name__ == '__main__':
parser.add_argument('--image_path', type=str,
default='test_images/det_images/')
parser.add_argument('--text_score', type=float, default=0.5)
+
+ parser.add_argument('--keys_path', type=str,
+ default="ch_ppocr_mobile_v2_rec/ppocr_keys_v1.txt")
args = parser.parse_args()
text_score = args.text_score
@@ -284,7 +288,8 @@ if __name__ == '__main__':
text_sys = TextSystem(args.det_model_path,
args.rec_model_path,
use_angle_cls=True,
- cls_model_path=args.cls_model_path)
+ cls_model_path=args.cls_model_path,
+ keys_path=args.keys_path)
image_file_list = get_image_file_list(args.image_path)
for image_path in image_file_list:
diff --git a/python/rapidOCR.sh b/python/rapidOCR.sh
index a8afaf0..a27e3d9 100644
--- a/python/rapidOCR.sh
+++ b/python/rapidOCR.sh
@@ -3,8 +3,10 @@
# The img_path can be file path or folder path.
img_path="test_images/det_images/1.jpg"
+key_path="ch_ppocr_mobile_v2_rec/ppocr_keys_v1.txt"
python rapidOCR.py --det_model_path models/ch_ppocr_mobile_v2.0_det_infer.onnx \
--cls_model_path models/ch_ppocr_mobile_v2.0_cls_infer.onnx \
--rec_model_path models/ch_ppocr_mobile_v2.0_rec_infer.onnx \
--image_path ${img_path} \
- --text_score 0.5
+ --text_score 0.5 \
+ --key_path ${key_path}