Paddle2ONNX icon indicating copy to clipboard operation
Paddle2ONNX copied to clipboard

请问怎么转换有三个model directory的PaddleOCR?

Open yxyphoebe opened this issue 4 years ago • 7 comments

现在的model是一个PaddleOCR class, 有三个model_dir,请问是要分开转换成ONNX吗?转换之后怎么combine起来,还有怎么用onnxruntime呢?

yxyphoebe avatar Feb 16 '21 02:02 yxyphoebe

@yxyphoebe 可以参考这个教程 https://aistudio.baidu.com/aistudio/projectdetail/1479970

Channingss avatar Feb 16 '21 03:02 Channingss

好的,谢谢,照着这个tutorial做,遇到这个问题,不知道有没有人遇到过。 (1150, 720, 3) Traceback (most recent call last): File "paddleocr/tools/infer/predict_system.py", line 190, in main(utility.parse_args()) File "paddleocr/tools/infer/predict_system.py", line 159, in main dt_boxes, rec_res = text_sys(img) File "paddleocr/tools/infer/predict_system.py", line 89, in call dt_boxes, elapse = self.text_detector(img) File "/Users/xinyyu/workspace/vision-service-model-deploy/ocr/ocr-mobilenet-onnx/paddleocr/tools/infer/predict_det.py", line 170, in call outputs = self.predictor.run(self.output_tensors, input_dict) File "/usr/local/Cellar/pyenv/1.2.7/versions/3.7.0/lib/python3.7/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 124, in run return self._sess.run(output_names, input_feed, run_options) onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Got invalid dimensions for input: x for the following indices index: 2 Got: 960 Expected: 640 index: 3 Got: 608 Expected: 640 Please fix either the inputs or the model.

yxyphoebe avatar Feb 17 '21 21:02 yxyphoebe

请问是怎么把model 的input shape改成 -1 x 3 x -1 x -1 的 @Channingss

yxyphoebe avatar Feb 17 '21 23:02 yxyphoebe

请PaddleOCR的release/2.0分支现在支持导出为动态shape的模型: https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.0/tools/export_model.py 这个是导出inference模型的教程: https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.0/doc/doc_ch/inference.md

Channingss avatar Feb 18 '21 02:02 Channingss

@Channingss 请问官方提供的inference model在转换后只能输入100的宽度,这块如何修改为动态输入呢

MagicCodess avatar Apr 06 '21 09:04 MagicCodess

+1

daixiangzi avatar Apr 28 '21 08:04 daixiangzi

可以参考下面的代码

    onnx_model = onnx.load(onnx_path)
    onnx.checker.check_model(onnx_model)
    print(f'The {onnx_path} is checked!')

    # 修改NCHW中H为动态输入
    onnx_model.graph.input[0].type.tensor_type.shape.dim[2].dim_param = '?'

    # 修改NCHW中W为动态输入
    onnx_model.graph.input[0].type.tensor_type.shape.dim[3].dim_param = '?'
    onnx.save(onnx_model, onnx_path)

SWHL avatar Jun 23 '21 09:06 SWHL

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jul 01 '25 03:07 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jul 17 '25 03:07 github-actions[bot]