Skip to content

Commit 6e61acd

Browse files
committed
docs: add v5 convert
1 parent 9dd4315 commit 6e61acd

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

docs/blog/posts/about_model/adapt_PP-OCRv5_mobile_det.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,30 +136,42 @@ Traceback (most recent call last):
136136
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from /Users/xxxx/projects/LittleCode/models/PP-OCRv5_mobile_det/inference.onnx failed:/Users/runner/work/1/s/onnxruntime/core/graph/model.cc:182 onnxruntime::Model::Model(ModelProto &&, const PathString &, const IOnnxRuntimeOpSchemaRegistryList *, const logging::Logger &, const ModelOptions &) Unsupported model IR version: 11, max supported IR version: 10
137137
```
138138
139-
经过一系列的查阅资料,终于在onnxruntime issue [#23602](https://github.com/microsoft/onnxruntime/issues/23602#issuecomment-2642348849) 中发现了解决方案。运行下面代码,将上一步所得模型重新指定一下**IR_VERSION**,就可以用`rapidocr`加载推理了
139+
经过一系列的查阅资料,发现了两种解决方案,经过测试,精度一样
140140
141-
```python linenums="1"
142-
import onnx
143-
from onnx import version_converter
141+
=== 方案一
144142
145-
OPT_VERSION = 14
146-
IR_VERSION = 10
143+
安装`onnx==1.16.0`,然后再次尝试转换。我这里实际测过,的确可以成功转换。
147144
148-
source_path = "models/PP-OCRv5_mobile_det/inference.onnx"
149-
dist_path = "models/PP-OCRv5_mobile_det/inference_v2.onnx"
145+
=== 方案二
150146
151-
model = onnx.load(source_path)
152-
model.ir_version = IR_VERSION
153-
model = version_converter.convert_version(model, OPT_VERSION)
154-
onnx.save(model, dist_path)
155-
```
147+
方案来自:onnxruntime issue [#23602](https://github.com/microsoft/onnxruntime/issues/23602#issuecomment-2642348849)
148+
149+
运行下面代码,将上一步所得模型重新指定一下**IR_VERSION**,就可以用`rapidocr`加载推理了。
150+
151+
```python linenums="1"
152+
import onnx
153+
from onnx import version_converter
154+
155+
OPT_VERSION = 14
156+
IR_VERSION = 10
157+
158+
source_path = "models/PP-OCRv5_mobile_det/inference.onnx"
159+
dist_path = "models/PP-OCRv5_mobile_det/inference_v2.onnx"
160+
161+
model = onnx.load(source_path)
162+
model.ir_version = IR_VERSION
163+
model = version_converter.convert_version(model, OPT_VERSION)
164+
onnx.save(model, dist_path)
165+
```
156166
157167
### 3. 模型推理验证
158168
159169
该部分主要是在RapidOCR项目中测试能否直接使用onnx模型。要点主要是确定模型前后处理是否兼容。从PaddleOCR config文件中比较[PP-OCRv4](https://github.com/PaddlePaddle/PaddleOCR/blob/549d83a88b7c75144120e6ec03de80d3eb9e48a5/configs/det/PP-OCRv4/PP-OCRv4_mobile_det.yml)和[PP-OCRv5 mobile det](https://github.com/PaddlePaddle/PaddleOCR/blob/549d83a88b7c75144120e6ec03de80d3eb9e48a5/configs/det/PP-OCRv5/PP-OCRv5_mobile_det.yml)文件差异:
160170
161171
![alt text](../images/v4_v5_mobile_det.png)
162172
173+
从上图中可以看出,配置基本一模一样,因为现有`rapidocr`前后推理代码可以直接使用。
174+
163175
```python linenums="1"
164176
from rapidocr import RapidOCR
165177
@@ -177,6 +189,13 @@ result.vis("vis_result.jpg")
177189
178190
### 4. 模型精度测试
179191
192+
!!! warning
193+
194+
测试集[text_det_test_dataset](https://huggingface.co/datasets/SWHL/text_det_test_dataset)包括卡证类、文档类和自然场景三大类。其中卡证类有82张,文档类有75张,自然场景类有55张。缺少手写体、繁体、日文、古籍文本、拼音、艺术字等数据。因此,该基于该测评集的结果仅供参考。
195+
196+
欢迎有兴趣的小伙伴,可以和我们一起共建更加完整的测评集。
197+
198+
180199
该部分主要使用[TextDetMetric](https://github.com/SWHL/TextDetMetric)和测试集[text_det_test_dataset](https://huggingface.co/datasets/SWHL/text_det_test_dataset)来评测。
181200
182201
相关测试步骤请参见[TextDetMetric](https://github.com/SWHL/TextRecMetric)的README,一步一步来就行。我这里测试最终精度如下:

docs/blog/posts/about_model/model_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ comments: true
5252
评测依赖仓库:
5353

5454
- `rapidocr_onnxruntime==1.3.16`: [link](https://github.com/RapidAI/RapidOCR)
55+
- `rapidocr==2.1.0`: [link](https://github.com/RapidAI/RapidOCR)
5556
- 计算指标库 TextDetMetric: [link](https://github.com/SWHL/TextDetMetric)
5657
- 测试集 text_det_test_dataset: [link](https://huggingface.co/datasets/SWHL/text_det_test_dataset)
5758

5859
详情可以移步[AI Studio](https://aistudio.baidu.com/projectdetail/6679889?sUid=57084&shared=1&ts=1693054678460)运行查看。
5960

6061
| 模型 | 模型大小| Precision | Recall | H-mean | Speed(s/img) |
6162
| :---------------------------- | :----------------: | :-------: | :----: | :----: | :------ |
63+
| ch_PP-OCRv5_mobile_det_infer.onnx | 4.6M | 0.7861 | 0.8266 | 0.8058 | 0.1482 |
6264
| ch_PP-OCRv4_det_infer.onnx | 4.5M | 0.8301 | 0.8659 | 0.8476 | 0.2256 |
6365
| ch_PP-OCRv3_det_infer.onnx | 2.3M | 0.8021 | 0.8457 | 0.8234 | 0.1660 |
6466
| ch_PP-OCRv2_det_infer.onnx | 2.2M | 0.7579 | 0.8010 | 0.7788 | 0.1570 |

0 commit comments

Comments
 (0)