Skip to content

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

Add test_images_benchmark

SWHL920cd1c5e4b7
diff --git a/README.md b/README.md
index 1424bbb..03309c7 100755
--- a/README.md
+++ b/README.md
@@ -197,11 +197,13 @@
- 非常感谢[lzh111222334](https://github.com/lzh111222334)修复python版本下rec前处理部分bug。
## 赞助
-
|赞助者|应用的产品|
|:---:|:---:|
|<a href="https://github.com/cuiliang" title="cuiliang"><img src="https://avatars.githubusercontent.com/u/1972649?v=4" width=65 height=65></a>|<a href="https://getquicker.net/" title="Quicker指尖工具箱"><img src="https://tvax2.sinaimg.cn/crop.0.0.600.600.180/82cedfe9ly8h0gd3koj1qj20go0goq34.jpg?KID=imgbed,tva&Expires=1657299650&ssig=7MKPeFM6RU" width=65 height=65></a>|
+- 如果您想要赞助该项目,可直接点击当前页最上面的Sponsor按钮,请写好备注,方便添加到上面赞助列表中。
+
+
## 版权声明
- 如果你的产品使用了本仓库中的全部或部分代码、文字或材料
- 请注明出处并包括我们的github url: `https://github.com/RapidAI/RapidOCR`
diff --git a/images/README.md b/images/README.md
new file mode 100755
index 0000000..2f89385
--- /dev/null
+++ b/images/README.md
@@ -0,0 +1,12 @@
+#### test_images_benchmark
+- 基准的测试图像,便于测试情况下统一基准,主要用于评测推理性能,侧重于速度方面。
+- 一共251张图像,类型涉及自然场景、文档类、广告海报、卡证类和手写体等样式,涉及语种为中英文。
+
+#### 下载链接
+- [百度网盘](链接:https://pan.baidu.com/s/1R4gYtJt2G3ypGkLWGwUCKg?pwd=ceuo)
+- [Google Drive](https://drive.google.com/drive/folders/1IIOCcUXdWa43Tfpsiy6UQJmPsZLnmgFh?usp=sharing)
+
+#### 贡献者
+<p align="left">
+ <a href="https://github.com/zhsunlight"><img src="https://avatars.githubusercontent.com/u/56898908?v=4" width=65 height=65></a>
+</p>
\ No newline at end of file
diff --git a/images/readme.md b/images/readme.md
deleted file mode 100755
index c47f362..0000000
--- a/images/readme.md
+++ /dev/null
@@ -1,2 +0,0 @@
-Files here are to be tested by api4CPP.
-They are two kinds of typical files: an arbitrary scenario and an long text scenario
diff --git a/python/README.md b/python/README.md
index e66c5c2..06f067d 100755
--- a/python/README.md
+++ b/python/README.md
@@ -200,4 +200,33 @@
do_copy_in_default_stream: true
```
-3. 推理情况(待更新)
+3. 推理情况
+ 1. 下载基准测试数据集(`test_images_benchmark`),放到`tests/benchmark`目录下。
+ - [百度网盘](链接:https://pan.baidu.com/s/1R4gYtJt2G3ypGkLWGwUCKg?pwd=ceuo) | [Google Drive](https://drive.google.com/drive/folders/1IIOCcUXdWa43Tfpsiy6UQJmPsZLnmgFh?usp=sharing)
+ - 最终目录结构如下:
+ ```text
+ tests/benchmark/
+ ├── benchmark.py
+ ├── config_gpu.yaml
+ ├── config.yaml
+ └── test_images_benchmark
+ ```
+ 2. 运行以下代码(`python`目录下运行):
+ ```shell
+ # CPU
+ python tests/benchmark/benchmark.py --yaml_path config.yaml
+
+ # GPU
+ python tests/benchmark/benchmark.py --yaml_path config_gpu.yaml
+ ```
+ 3. 运行相关信息汇总:
+ - 设备型号:
+ - GPU型号:
+ - CPU型号:
+ - 耗时情况:
+
+ |设备|总耗时(s)|平均耗时(s/img)|
+ |:---:|:---:|:---:|
+ |CPU|||
+ |GPU|||
+
diff --git a/python/rapidocr_onnxruntime/ch_ppocr_v2_det/utils.py b/python/rapidocr_onnxruntime/ch_ppocr_v2_det/utils.py
index 674ed8b..e5afe48 100644
--- a/python/rapidocr_onnxruntime/ch_ppocr_v2_det/utils.py
+++ b/python/rapidocr_onnxruntime/ch_ppocr_v2_det/utils.py
@@ -390,10 +390,10 @@ class DBPostProcess(object):
def box_score_fast(self, bitmap, _box):
h, w = bitmap.shape[:2]
box = _box.copy()
- xmin = np.clip(np.floor(box[:, 0].min()).astype(np.int), 0, w - 1)
- xmax = np.clip(np.ceil(box[:, 0].max()).astype(np.int), 0, w - 1)
- ymin = np.clip(np.floor(box[:, 1].min()).astype(np.int), 0, h - 1)
- ymax = np.clip(np.ceil(box[:, 1].max()).astype(np.int), 0, h - 1)
+ xmin = np.clip(np.floor(box[:, 0].min()).astype(np.int32), 0, w - 1)
+ xmax = np.clip(np.ceil(box[:, 0].max()).astype(np.int32), 0, w - 1)
+ ymin = np.clip(np.floor(box[:, 1].min()).astype(np.int32), 0, h - 1)
+ ymax = np.clip(np.ceil(box[:, 1].max()).astype(np.int32), 0, h - 1)
mask = np.zeros((ymax - ymin + 1, xmax - xmin + 1), dtype=np.uint8)
box[:, 0] = box[:, 0] - xmin
diff --git a/python/rapidocr_openvino/ch_ppocr_v2_det/utils.py b/python/rapidocr_openvino/ch_ppocr_v2_det/utils.py
index 6c75b66..57fc11d 100644
--- a/python/rapidocr_openvino/ch_ppocr_v2_det/utils.py
+++ b/python/rapidocr_openvino/ch_ppocr_v2_det/utils.py
@@ -365,10 +365,10 @@ class DBPostProcess(object):
def box_score_fast(self, bitmap, _box):
h, w = bitmap.shape[:2]
box = _box.copy()
- xmin = np.clip(np.floor(box[:, 0].min()).astype(np.int), 0, w - 1)
- xmax = np.clip(np.ceil(box[:, 0].max()).astype(np.int), 0, w - 1)
- ymin = np.clip(np.floor(box[:, 1].min()).astype(np.int), 0, h - 1)
- ymax = np.clip(np.ceil(box[:, 1].max()).astype(np.int), 0, h - 1)
+ xmin = np.clip(np.floor(box[:, 0].min()).astype(np.int32), 0, w - 1)
+ xmax = np.clip(np.ceil(box[:, 0].max()).astype(np.int32), 0, w - 1)
+ ymin = np.clip(np.floor(box[:, 1].min()).astype(np.int32), 0, h - 1)
+ ymax = np.clip(np.ceil(box[:, 1].max()).astype(np.int32), 0, h - 1)
mask = np.zeros((ymax - ymin + 1, xmax - xmin + 1), dtype=np.uint8)
box[:, 0] = box[:, 0] - xmin
diff --git a/python/tests/benchmark/benchmark.py b/python/tests/benchmark/benchmark.py
new file mode 100644
index 0000000..0855e8f
--- /dev/null
+++ b/python/tests/benchmark/benchmark.py
@@ -0,0 +1,45 @@
+# -*- encoding: utf-8 -*-
+# @Author: SWHL
+# @Contact: [email protected]
+import argparse
+from pathlib import Path
+from tqdm import tqdm
+import sys
+import time
+
+cur_dir = Path(__file__).resolve().parent
+sys.path.append(str(cur_dir.parent.parent))
+
+import cv2
+from rapidocr_onnxruntime import TextSystem
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--yaml_path', type=str, default='config.yaml')
+ args = parser.parse_args()
+
+ yaml_path = cur_dir / args.yaml_path
+ text_sys = TextSystem(yaml_path)
+
+ image_dir = cur_dir / 'test_images_benchmark'
+ if not image_dir.exists():
+ raise FileNotFoundError(f'{image_dir} does not exits!!')
+
+ image_list = list(image_dir.iterdir())
+
+ cost_time_list = []
+ for image_path in tqdm(image_list, desc='Test'):
+ img = cv2.imread(str(image_path))
+
+ start_time = time.time()
+ dt_boxes, rec_res = text_sys(img)
+ elapse = time.time() - start_time
+
+ cost_time_list.append(elapse)
+
+ total_time = sum(cost_time_list)
+ avg_time = total_time / len(cost_time_list)
+ print(f'Total Files: {len(image_list)}, '
+ f'Total Time: {total_time:.5f}, '
+ f'Average Time: {avg_time:.5f}')
diff --git a/python/tests/benchmark/config.yaml b/python/tests/benchmark/config.yaml
new file mode 100644
index 0000000..4b5b414
--- /dev/null
+++ b/python/tests/benchmark/config.yaml
@@ -0,0 +1,71 @@
+Global:
+ text_score: 0.5
+ use_angle_cls: true
+ print_verbose: false
+ min_height: 30
+
+Det:
+ module_name: ch_ppocr_v2_det
+ class_name: TextDetector
+ model_path: resources/models/ch_PP-OCRv3_det_infer.onnx
+
+ use_cuda: false
+ # Details of the params: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
+ CUDAExecutionProvider:
+ device_id: 0
+ arena_extend_strategy: kNextPowerOfTwo
+ cudnn_conv_algo_search: EXHAUSTIVE
+ do_copy_in_default_stream: true
+
+ pre_process:
+ DetResizeForTest:
+ limit_side_len: 736
+ limit_type: min
+ NormalizeImage:
+ std: [0.229, 0.224, 0.225]
+ mean: [0.485, 0.456, 0.406]
+ scale: 1./255.
+ order: hwc
+ ToCHWImage:
+ KeepKeys:
+ keep_keys: ['image', 'shape']
+
+ post_process:
+ thresh: 0.3
+ box_thresh: 0.5
+ max_candidates: 1000
+ unclip_ratio: 1.6
+ use_dilation: true
+
+Cls:
+ module_name: ch_ppocr_v2_cls
+ class_name: TextClassifier
+ model_path: resources/models/ch_ppocr_mobile_v2.0_cls_infer.onnx
+
+ use_cuda: false
+ CUDAExecutionProvider:
+ device_id: 0
+ arena_extend_strategy: kNextPowerOfTwo
+ cudnn_conv_algo_search: EXHAUSTIVE
+ do_copy_in_default_stream: true
+
+ cls_image_shape: [3, 48, 192]
+ cls_batch_num: 6
+ cls_thresh: 0.9
+ label_list: ['0', '180']
+
+Rec:
+ module_name: ch_ppocr_v2_rec
+ class_name: TextRecognizer
+ model_path: resources/models/ch_PP-OCRv3_rec_infer.onnx
+
+ use_cuda: false
+ CUDAExecutionProvider:
+ device_id: 0
+ arena_extend_strategy: kNextPowerOfTwo
+ cudnn_conv_algo_search: EXHAUSTIVE
+ do_copy_in_default_stream: true
+
+ rec_img_shape: [3, 48, 320]
+ rec_batch_num: 6
+ keys_path: resources/rec_dict/ppocr_keys_v1.txt
diff --git a/python/tests/benchmark/config_gpu.yaml b/python/tests/benchmark/config_gpu.yaml
new file mode 100644
index 0000000..c8d3156
--- /dev/null
+++ b/python/tests/benchmark/config_gpu.yaml
@@ -0,0 +1,71 @@
+Global:
+ text_score: 0.5
+ use_angle_cls: true
+ print_verbose: false
+ min_height: 30
+
+Det:
+ module_name: ch_ppocr_v2_det
+ class_name: TextDetector
+ model_path: resources/models/ch_PP-OCRv3_det_infer.onnx
+
+ use_cuda: true
+ # Details of the params: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
+ CUDAExecutionProvider:
+ device_id: 0
+ arena_extend_strategy: kNextPowerOfTwo
+ cudnn_conv_algo_search: EXHAUSTIVE
+ do_copy_in_default_stream: true
+
+ pre_process:
+ DetResizeForTest:
+ limit_side_len: 736
+ limit_type: min
+ NormalizeImage:
+ std: [0.229, 0.224, 0.225]
+ mean: [0.485, 0.456, 0.406]
+ scale: 1./255.
+ order: hwc
+ ToCHWImage:
+ KeepKeys:
+ keep_keys: ['image', 'shape']
+
+ post_process:
+ thresh: 0.3
+ box_thresh: 0.5
+ max_candidates: 1000
+ unclip_ratio: 1.6
+ use_dilation: true
+
+Cls:
+ module_name: ch_ppocr_v2_cls
+ class_name: TextClassifier
+ model_path: resources/models/ch_ppocr_mobile_v2.0_cls_infer.onnx
+
+ use_cuda: true
+ CUDAExecutionProvider:
+ device_id: 0
+ arena_extend_strategy: kNextPowerOfTwo
+ cudnn_conv_algo_search: EXHAUSTIVE
+ do_copy_in_default_stream: true
+
+ cls_image_shape: [3, 48, 192]
+ cls_batch_num: 6
+ cls_thresh: 0.9
+ label_list: ['0', '180']
+
+Rec:
+ module_name: ch_ppocr_v2_rec
+ class_name: TextRecognizer
+ model_path: resources/models/ch_PP-OCRv3_rec_infer.onnx
+
+ use_cuda: true
+ CUDAExecutionProvider:
+ device_id: 0
+ arena_extend_strategy: kNextPowerOfTwo
+ cudnn_conv_algo_search: EXHAUSTIVE
+ do_copy_in_default_stream: true
+
+ rec_img_shape: [3, 48, 320]
+ rec_batch_num: 6
+ keys_path: resources/rec_dict/ppocr_keys_v1.txt