Skip to content

Commit 335c5c2

Browse files
MrxubaGreatV
andauthored
[doc] fixing broken links and updating paddle2onnx usage descriptions (#12749)
* [docs]:添加了对于Paddle2ONNX模型转化中选项--input_shape_dict的解释说明与解决方法 * Update readme_ch.md [docs]:使用onnxsim修改input_shape可以兼容paddlepaddle现版本 * Update readme_ch.md 修改了不恰当的相关描述 * Rename inference_ch.md to inference.md 修改了中文版模型导出说明inference_ch.md命名为inference.md * Update readme_ch.md 修改不恰当表述 * Update readme_ch.md 修改所有python3.7为python3 * update readme --------- Co-authored-by: Wang Xin <[email protected]>
1 parent 86a447d commit 335c5c2

File tree

3 files changed

+448
-35
lines changed

3 files changed

+448
-35
lines changed

deploy/paddle2onnx/readme.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Need to prepare PaddleOCR, Paddle2ONNX model conversion environment, and ONNXRun
88

99
### PaddleOCR
1010

11-
Clone the PaddleOCR repository, use the release/2.6 branch, and install it.
11+
Clone the PaddleOCR repository, use the main branch, and install it.
1212

1313
```
14-
git clone -b release/2.6 https://github.com/PaddlePaddle/PaddleOCR.git
15-
cd PaddleOCR && python3.7 setup.py install
14+
git clone -b main https://github.com/PaddlePaddle/PaddleOCR.git
15+
cd PaddleOCR && python3 pip install -e .
1616
```
1717

1818
### Paddle2ONNX
@@ -23,13 +23,12 @@ For more details, please refer to [Paddle2ONNX](https://github.com/PaddlePaddle/
2323

2424
- install Paddle2ONNX
2525
```
26-
python3.7 -m pip install paddle2onnx
26+
python3 -m pip install paddle2onnx
2727
```
2828

2929
- install ONNXRuntime
3030
```
31-
# It is recommended to install version 1.9.0, and the version number can be changed according to the environment
32-
python3.7 -m pip install onnxruntime==1.9.0
31+
python3 -m pip install onnxruntime
3332
```
3433

3534
## 2. Model conversion
@@ -62,32 +61,37 @@ paddle2onnx --model_dir ./inference/en_PP-OCRv3_det_infer \
6261
--model_filename inference.pdmodel \
6362
--params_filename inference.pdiparams \
6463
--save_file ./inference/det_onnx/model.onnx \
65-
--opset_version 10 \
66-
--input_shape_dict="{'x':[-1,3,-1,-1]}" \
64+
--opset_version 11 \
6765
--enable_onnx_checker True
6866
6967
paddle2onnx --model_dir ./inference/en_PP-OCRv3_rec_infer \
7068
--model_filename inference.pdmodel \
7169
--params_filename inference.pdiparams \
7270
--save_file ./inference/rec_onnx/model.onnx \
73-
--opset_version 10 \
74-
--input_shape_dict="{'x':[-1,3,-1,-1]}" \
71+
--opset_version 11 \
7572
--enable_onnx_checker True
7673
7774
paddle2onnx --model_dir ./inference/ch_ppocr_mobile_v2.0_cls_infer \
78-
--model_filename ch_ppocr_mobile_v2.0_cls_infer/inference.pdmodel \
79-
--params_filename ch_ppocr_mobile_v2.0_cls_infer/inference.pdiparams \
80-
--save_file ./inferencecls_onnx/model.onnx \
81-
--opset_version 10 \
82-
--input_shape_dict="{'x':[-1,3,-1,-1]}" \
75+
--model_filename inference.pdmodel \
76+
--params_filename inference.pdiparams \
77+
--save_file ./inference/cls_onnx/model.onnx \
78+
--opset_version 11 \
8379
--enable_onnx_checker True
8480
```
8581
After execution, the ONNX model will be saved in `./inference/det_onnx/`, `./inference/rec_onnx/`, `./inference/cls_onnx/` paths respectively
8682

87-
* Note: For the OCR model, the conversion process must be in the form of dynamic shape, that is, add the option --input_shape_dict="{'x': [-1, 3, -1, -1]}", otherwise the prediction result may be the same as Predicting directly with Paddle is slightly different.
83+
* Note: For the OCR model, the conversion process must be in the form of dynamic shape, otherwise the prediction result may be the same as Predicting directly with Paddle is slightly different.
8884
In addition, the following models do not currently support conversion to ONNX models:
8985
NRTR, SAR, RARE, SRN
9086

87+
* Note: The current Paddle2ONNX version (v1.2.3) now supports dynamic shapes by default, i.e., float32[p2o.DynamicDimension.0,3,p2o.DynamicDimension.1,p2o.DynamicDimension.2]. The `--input_shape_dict` option has been deprecated. If you need to adjust the shape, you can use the following command to adjust the input shape of the Paddle model.
88+
89+
```
90+
python3 -m paddle2onnx.optimize --input_model inference/det_onnx/model.onnx \
91+
--output_model inference/det_onnx/model.onnx \
92+
--input_shape_dict "{'x': [-1,3,-1,-1]}"
93+
```
94+
9195
## 3. prediction
9296

9397
Take the English OCR model as an example, use **ONNXRuntime** to predict and execute the following commands:

deploy/paddle2onnx/readme_ch.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,26 @@
88

99
### PaddleOCR
1010

11-
克隆PaddleOCR的仓库,使用release/2.4分支,并进行安装,由于PaddleOCR仓库比较大,git clone速度比较慢,所以本教程已下载
11+
克隆PaddleOCR的仓库,使用 main 分支,并进行安装,由于 PaddleOCR 仓库比较大,git clone 速度比较慢,所以本教程已下载
1212

1313
```
14-
git clone -b release/2.4 https://github.com/PaddlePaddle/PaddleOCR.git
15-
cd PaddleOCR && python3.7 setup.py install
14+
git clone -b main https://github.com/PaddlePaddle/PaddleOCR.git
15+
cd PaddleOCR && python3 -m pip install -e .
1616
```
1717

1818
### Paddle2ONNX
1919

20-
Paddle2ONNX 支持将 PaddlePaddle 模型格式转化到 ONNX 模型格式,算子目前稳定支持导出 ONNX Opset 9~11,部分Paddle算子支持更低的ONNX Opset转换。
20+
Paddle2ONNX 支持将 PaddlePaddle 模型格式转化到 ONNX 模型格式,算子目前稳定支持导出 ONNX Opset 9~18,部分Paddle算子支持更低的ONNX Opset转换。
2121
更多细节可参考 [Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX/blob/develop/README_zh.md)
2222

2323
- 安装 Paddle2ONNX
2424
```
25-
python3.7 -m pip install paddle2onnx
25+
python3 -m pip install paddle2onnx
2626
```
2727

2828
- 安装 ONNXRuntime
2929
```
30-
# 建议安装 1.9.0 版本,可根据环境更换版本号
31-
python3.7 -m pip install onnxruntime==1.9.0
30+
python3 -m pip install onnxruntime
3231
```
3332

3433
## 2. 模型转换
@@ -61,39 +60,44 @@ paddle2onnx --model_dir ./inference/ch_PP-OCRv3_det_infer \
6160
--model_filename inference.pdmodel \
6261
--params_filename inference.pdiparams \
6362
--save_file ./inference/det_onnx/model.onnx \
64-
--opset_version 10 \
65-
--input_shape_dict="{'x':[-1,3,-1,-1]}" \
63+
--opset_version 11 \
6664
--enable_onnx_checker True
6765
6866
paddle2onnx --model_dir ./inference/ch_PP-OCRv3_rec_infer \
6967
--model_filename inference.pdmodel \
7068
--params_filename inference.pdiparams \
7169
--save_file ./inference/rec_onnx/model.onnx \
72-
--opset_version 10 \
73-
--input_shape_dict="{'x':[-1,3,-1,-1]}" \
70+
--opset_version 11 \
7471
--enable_onnx_checker True
7572
7673
paddle2onnx --model_dir ./inference/ch_ppocr_mobile_v2.0_cls_infer \
77-
--model_filename ch_ppocr_mobile_v2.0_cls_infer/inference.pdmodel \
78-
--params_filename ch_ppocr_mobile_v2.0_cls_infer/inference.pdiparams \
79-
--save_file ./inferencecls_onnx/model.onnx \
80-
--opset_version 10 \
81-
--input_shape_dict="{'x':[-1,3,-1,-1]}" \
74+
--model_filename inference.pdmodel \
75+
--params_filename inference.pdiparams \
76+
--save_file ./inference/cls_onnx/model.onnx \
77+
--opset_version 11 \
8278
--enable_onnx_checker True
8379
```
8480

8581
执行完毕后,ONNX 模型会被分别保存在 `./inference/det_onnx/``./inference/rec_onnx/``./inference/cls_onnx/`路径下
8682

87-
* 注意:对于OCR模型,转化过程中必须采用动态shape的形式,即加入选项--input_shape_dict="{'x': [-1, 3, -1, -1]}",否则预测结果可能与直接使用Paddle预测有细微不同。
83+
* 注意:对于OCR模型,转化过程中必须采用动态shape的形式,否则预测结果可能与直接使用Paddle预测有细微不同。
8884
另外,以下几个模型暂不支持转换为 ONNX 模型:
8985
NRTR、SAR、RARE、SRN
9086

87+
* 注意:[当前Paddle2ONNX版本(v1.2.3)](https://github.com/PaddlePaddle/Paddle2ONNX/releases/tag/v1.2.3)现已默认支持动态shape,即 `float32[p2o.DynamicDimension.0,3,p2o.DynamicDimension.1,p2o.DynamicDimension.2]`,选项 `--input_shape_dict` 已废弃。如果有shape调整需求可使用如下命令进行Paddle模型输入shape调整。
88+
89+
```
90+
python3 -m paddle2onnx.optimize --input_model inference/det_onnx/model.onnx \
91+
--output_model inference/det_onnx/model.onnx \
92+
--input_shape_dict "{'x': [-1,3,-1,-1]}"
93+
```
94+
9195
## 3. 推理预测
9296

9397
以中文OCR模型为例,使用 ONNXRuntime 预测可执行如下命令:
9498

9599
```
96-
python3.7 tools/infer/predict_system.py --use_gpu=False --use_onnx=True \
100+
python3 tools/infer/predict_system.py --use_gpu=False --use_onnx=True \
97101
--det_model_dir=./inference/det_onnx/model.onnx \
98102
--rec_model_dir=./inference/rec_onnx/model.onnx \
99103
--cls_model_dir=./inference/cls_onnx/model.onnx \
@@ -103,7 +107,7 @@ python3.7 tools/infer/predict_system.py --use_gpu=False --use_onnx=True \
103107
以中文OCR模型为例,使用 Paddle Inference 预测可执行如下命令:
104108

105109
```
106-
python3.7 tools/infer/predict_system.py --use_gpu=False \
110+
python3 tools/infer/predict_system.py --use_gpu=False \
107111
--cls_model_dir=./inference/ch_ppocr_mobile_v2.0_cls_infer \
108112
--rec_model_dir=./inference/ch_PP-OCRv3_rec_infer \
109113
--det_model_dir=./inference/ch_PP-OCRv3_det_infer \

0 commit comments

Comments
 (0)