Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PaddleOCR slim export model #12074

Closed
xiaoxifuhongse opened this issue May 8, 2024 · 5 comments
Closed

PaddleOCR slim export model #12074

xiaoxifuhongse opened this issue May 8, 2024 · 5 comments
Assignees
Labels
bug Something isn't working status/close

Comments

@xiaoxifuhongse
Copy link

xiaoxifuhongse commented May 8, 2024

请提供下述完整信息以便快速定位问题/Please provide the following information to quickly locate the problem

  • 系统环境/System Environment:Ubuntu20.04
  • 版本号/Version:Paddle: PaddleOCR: 问题相关组件/Related components:Paddleocr 2.8.0 paddlepaddle-gpu 2.6.0 paddleslim 2.6.0 paddle2onnx 1.2.1

I download inference_model frommodel_list and choose the ch_PP-OCRv3-det_slim ,then I want to convert to onnx model use cmd like this:

paddle2onnx --model_dir ./model/ch_PP-OCRv3_det_slim_infer --model_filename inference.pdmodel --params_filename inference.pdiparams --save_file ./model/rec_onnx/model.onnx --opset_version 10 --enable_onnx_checker True --input_shape_dict="{'x':[-1,3,-1,-1]}"

  1. it give me an error paddle2onnx: error: unrecognized arguments: --input_shape_dict={'x':[-1,3,-1,-1]},so I remove input_shape_dict ,so lots of toturial about paddle, give me the --input_shape_dict, so it remove it now?

  2. so I remove the --input_shape_dict of course it will give me an error like this:

[Paddle2ONNX] Oops, there are some operators not supported yet, including fake_channel_wise_quantize_dequantize_abs_max,fake_quantize_dequantize_moving_average_abs_max,
[ERROR] Due to the unsupported operators, the conversion is aborted.

I konw because it convert to inference model without onnx_format = True, so I Download the trained_model to get the best_accuracy.pdparams, so I make onnx_format=True and

python deploy/slim/quantization/export_model.py -c /home/xxDownloads/ch_PP-OCRv3_det_cml.yml -o Global.pretrained_model=/home/xx/Downloads/ch_PP-OCRv3_det_slim_distill_train/best_accuracy.pdparams Global.save_inference_dir=output/det/infer

  1. I get a new Inference.pdmodel just 300kb, and I download from model list model_list
    2.8M why?
  2. I eval the model I exported get wrong, I cant not get predict results but the model download can,so why?
  3. I make onnx_format=false I export _model again , the size just 300kb, not like 2.8M I downloads too, but I can get right predict result so why?
@Sunting78
Copy link
Collaborator

The quantitative export will quantize or prune the model parameters, making the model smaller. What is the specific error in question 4 ?

@hacktmz
Copy link

hacktmz commented May 14, 2024

我也是 编译之后还是存在找不到参数paddle2onnx: error: unrecognized arguments: --input_shape_dict={'x':[-1,3,-1,-1]}

@swdee
Copy link

swdee commented May 15, 2024

I get same error about unrecognized arguments on --input_shape_dict by following the docs here

$ paddle2onnx --version
2024-05-15 17:17:51 [INFO]      paddle2onnx-1.2.1 with python>=3.6, paddlepaddle>=2.0.0

$ paddle2onnx --model_dir ./japan_PP-OCRv3_rec_infer/ --model_filename inference.pdmodel --params_filename inference.pdiparams --save_file ./japanv3-rec.onnx --opset_version 11 --input_shape_dict="{'x':[-1,3,-1,-1]}" --enable_onnx_checker True 

usage: paddle2onnx [-h] [--model_dir MODEL_DIR] [--model_filename MODEL_FILENAME] [--params_filename PARAMS_FILENAME] [--save_file SAVE_FILE] [--opset_version OPSET_VERSION]
                   [--deploy_backend {onnxruntime,tensorrt,rknn,others}] [--save_calibration_file SAVE_CALIBRATION_FILE] [--enable_onnx_checker ENABLE_ONNX_CHECKER] [--enable_paddle_fallback ENABLE_PADDLE_FALLBACK]
                   [--version] [--enable_auto_update_opset ENABLE_AUTO_UPDATE_OPSET] [--external_filename EXTERNAL_FILENAME] [--export_fp16_model EXPORT_FP16_MODEL] [--custom_ops CUSTOM_OPS]

paddle2onnx: error: unrecognized arguments: --input_shape_dict={'x':[-1,3,-1,-1]}

@TingquanGao TingquanGao added the bug Something isn't working label May 16, 2024
@swdee
Copy link

swdee commented May 17, 2024

The real problem is the documentation being out of date. The --input_shape_dict is a deprecated argument. The instructions here show how to do this with current versions of paddle and paddle2onnx.

To summarise the following steps worked for me for converting the Japanese text model.

Install Paddle2ONNX.

pip3 install paddlepaddle
pip3 install paddle2onnx

Convert to ONNX.

paddle2onnx --model_dir ./japan_PP-OCRv3_rec_infer/ \
--model_filename inference.pdmodel \
--params_filename inference.pdiparams \
--save_file ./japanv3-rec.onnx

Change the Input shape parameters.

python3 -m paddle2onnx.optimize --input_model japanv3-rec.onnx \
--output_model japanv3-rec.onnx --input_shape_dict "{'x':[1,3,48,320]}"

@Sunting78
Copy link
Collaborator

您好,问题超过一周未回复将关闭。如有问题可重开issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working status/close
Projects
None yet
Development

No branches or pull requests

5 participants