Skip to content

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

Optim ocrweb

SWHLb92b388ce54d
diff --git a/ocrweb/README.md b/ocrweb/README.md
index 45040ff..3178135 100755
--- a/ocrweb/README.md
+++ b/ocrweb/README.md
@@ -20,15 +20,7 @@
</div>
### config.yaml全局参数说明
-```text
-Global:
- text_score: 0.5
- use_angle_cls: true # 是否使用文本框分类模型,默认为True
- use_text_det: true # 是否使用文本检测模型,默认为True
- print_verbose: true # 使用打印各个阶段的运行时长到终端,默认为True
- min_height: 30 # 图像高度小于30将不经过文本检测模型
- width_height_ratio: 8 # 图像宽高比大于该值,则不经过文本检测模型
-```
+- 详情参见:[README](../python/README.md#configyaml中常用参数介绍)
### 以Web方式运行
@@ -36,13 +28,12 @@ Global:
```shell
pip install -r requirements.txt -i https://pypi.douban.com/simple/
```
-2. 下载`resources`目录
+2. 下载`models`目录
- 下载链接:[百度网盘](https://pan.baidu.com/s/1PTcgXG2zEgQU6A_A3kGJ3Q?pwd=jhai) | [Google Drive](https://drive.google.com/drive/folders/1x_a9KpCo_1blxH1xFOfgKVkw1HYRVywY?usp=sharing)
- 最终目录结构如下:
```text
ocrweb
├── README.md
- ├── config.yaml
├── main.py
├── requirements.txt
├── task.py
@@ -51,8 +42,8 @@ Global:
│   ├── ch_ppocr_v3_det
│   ├── ch_ppocr_v2_cls
│   ├── ch_ppocr_v3_rec
- │   └── rapid_ocr_api.py
- ├── resources
+ │   ├── config.yaml
+ │   ├── rapid_ocr_api.py
│   └── models
│    ├── ch_PP-OCRv3_det_infer.onnx
│    ├── ch_ppocr_mobile_v2.0_cls_infer.onnx
diff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/config.yaml b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/config.yaml
index 89497ae..79e1a02 100644
--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/config.yaml
+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/config.yaml
@@ -1,4 +1,4 @@
-model_path: resources/models/ch_ppocr_mobile_v2.0_cls_infer.onnx
+model_path: models/ch_ppocr_mobile_v2.0_cls_infer.onnx
use_cuda: false
# Details of the params: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
diff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.py b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.py
index a15cd65..570a0b7 100644
--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.py
+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.py
@@ -18,6 +18,7 @@ import yaml
from onnxruntime import (get_available_providers, get_device,
SessionOptions, InferenceSession,
GraphOptimizationLevel)
+root_dir = Path(__file__).resolve().parent.parent
class OrtInferSession(object):
@@ -39,6 +40,7 @@ class OrtInferSession(object):
EP_list = [(cuda_ep, config[cuda_ep])]
EP_list.append((cpu_ep, cpu_provider_options))
+ config['model_path'] = str(root_dir / config['model_path'])
self._verify_model(config['model_path'])
self.session = InferenceSession(config['model_path'],
sess_options=sess_opt,
@@ -87,4 +89,4 @@ class ClsPostProcess(object):
return decode_out
label = [(self.label_list[idx], 1.0) for idx in label]
- return decode_out, label
\ No newline at end of file
+ return decode_out, label
diff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/config.yaml b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/config.yaml
index bafce72..c6d4073 100644
--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/config.yaml
+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/config.yaml
@@ -1,4 +1,4 @@
-model_path: resources/models/ch_PP-OCRv3_det_infer.onnx
+model_path: models/ch_PP-OCRv3_det_infer.onnx
use_cuda: false
# Details of the params: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
diff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py
index c2c9e17..0cdae63 100644
--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py
+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py
@@ -29,6 +29,7 @@ from shapely.geometry import Polygon
from onnxruntime import (get_available_providers, get_device,
SessionOptions, InferenceSession,
GraphOptimizationLevel)
+root_dir = Path(__file__).resolve().parent.parent
class OrtInferSession(object):
@@ -50,6 +51,7 @@ class OrtInferSession(object):
EP_list = [(cuda_ep, config[cuda_ep])]
EP_list.append((cpu_ep, cpu_provider_options))
+ config['model_path'] = str(root_dir / config['model_path'])
self._verify_model(config['model_path'])
self.session = InferenceSession(config['model_path'],
sess_options=sess_opt,
diff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/config.yaml b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/config.yaml
index 5df6390..1526f9b 100644
--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/config.yaml
+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/config.yaml
@@ -1,4 +1,4 @@
-model_path: resources/models/ch_PP-OCRv3_rec_infer.onnx
+model_path: models/ch_PP-OCRv3_rec_infer.onnx
use_cuda: false
# Details of the params: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
diff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py
index 1938404..954c4f8 100644
--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py
+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py
@@ -9,6 +9,7 @@ import yaml
from onnxruntime import (get_available_providers, get_device,
SessionOptions, InferenceSession,
GraphOptimizationLevel)
+root_dir = Path(__file__).resolve().parent.parent
class OrtInferSession(object):
@@ -30,6 +31,7 @@ class OrtInferSession(object):
EP_list = [(cuda_ep, config[cuda_ep])]
EP_list.append((cpu_ep, cpu_provider_options))
+ config['model_path'] = str(root_dir / config['model_path'])
self._verify_model(config['model_path'])
self.session = InferenceSession(config['model_path'],
sess_options=sess_opt,
diff --git a/ocrweb/config.yaml b/ocrweb/rapidocr_onnxruntime/config.yaml
similarity index 90%
rename from ocrweb/config.yaml
rename to ocrweb/rapidocr_onnxruntime/config.yaml
index 81de531..4b849b7 100644
--- a/ocrweb/config.yaml
+++ b/ocrweb/rapidocr_onnxruntime/config.yaml
@@ -9,7 +9,7 @@ Global:
Det:
module_name: ch_ppocr_v3_det
class_name: TextDetector
- model_path: resources/models/ch_PP-OCRv3_det_infer.onnx
+ model_path: models/ch_PP-OCRv3_det_infer.onnx
use_cuda: false
# Details of the params: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
@@ -43,7 +43,7 @@ Det:
Cls:
module_name: ch_ppocr_v2_cls
class_name: TextClassifier
- model_path: resources/models/ch_ppocr_mobile_v2.0_cls_infer.onnx
+ model_path: models/ch_ppocr_mobile_v2.0_cls_infer.onnx
use_cuda: false
CUDAExecutionProvider:
@@ -60,7 +60,7 @@ Cls:
Rec:
module_name: ch_ppocr_v3_rec
class_name: TextRecognizer
- model_path: resources/models/ch_PP-OCRv3_rec_infer.onnx
+ model_path: models/ch_PP-OCRv3_rec_infer.onnx
use_cuda: false
CUDAExecutionProvider:
diff --git a/ocrweb/resources/fonts/.gitkeep b/ocrweb/rapidocr_onnxruntime/models/.gitkeep
similarity index 100%
rename from ocrweb/resources/fonts/.gitkeep
rename to ocrweb/rapidocr_onnxruntime/models/.gitkeep
diff --git a/ocrweb/rapidocr_onnxruntime/rapid_ocr_api.py b/ocrweb/rapidocr_onnxruntime/rapid_ocr_api.py
index a3f4d4f..9ade4d5 100644
--- a/ocrweb/rapidocr_onnxruntime/rapid_ocr_api.py
+++ b/ocrweb/rapidocr_onnxruntime/rapid_ocr_api.py
@@ -15,9 +15,12 @@ root_dir = Path(__file__).resolve().parent
sys.path.append(str(root_dir))
-class RapidOCR(object):
+class RapidOCR():
def __init__(self, config_path=str(root_dir / 'config.yaml')):
super(RapidOCR).__init__()
+ if not Path(config_path).exists():
+ raise FileExistsError(f'{config_path} does not exist!')
+
config = self.read_yaml(config_path)
global_config = config['Global']
diff --git a/ocrweb/resources/models/.gitkeep b/ocrweb/resources/models/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/ocrweb/task.py b/ocrweb/task.py
index d428d2c..29f7eeb 100644
--- a/ocrweb/task.py
+++ b/ocrweb/task.py
@@ -12,7 +12,7 @@ import numpy as np
from rapidocr_onnxruntime import RapidOCR
-text_sys = RapidOCR('config.yaml')
+text_sys = RapidOCR()
def detect_recognize(image_path, is_api=False):
diff --git a/ocrweb/templates/index.html b/ocrweb/templates/index.html
index 1eed084..497bdfa 100644
--- a/ocrweb/templates/index.html
+++ b/ocrweb/templates/index.html
@@ -3,12 +3,12 @@
<head>
<meta charset="UTF-8">
<title>RapidOCR Demo</title>
- <link rel=stylesheet type="text/css" href="{{url_for('static', filename='css/main.css')}}">
+ <link rel=stylesheet type="text/css" href="/static/css/main.css">
<link rel="shortcut icon" href="/static/css/favicon.ico" type="image/x-icon"/>
</head>
<body>
<h1 align="center">
- <b><i>Rapid🗲OCR Demo</i></b>&nbsp;
+ <b><i>RapidOCR Demo</i></b>&nbsp;
<a href="https://github.com/RapidAI/RapidOCR" style="font-size: 14px;">欢迎Star</a>&thinsp;
<a href="https://github.com/RapidAI/RapidOCR/tree/main/ocrweb#readme" style="font-size:14px">了解Demo</a>
</h1>