首页 PaddleOCR 帖子详情
paddle2onnx报错问题
收藏
快速回复
PaddleOCR 问答OCR 2925 1
paddle2onnx报错问题
收藏
快速回复
PaddleOCR 问答OCR 2925 1

我用paddle2onnx将paddleocr的检测与识别模型转化为onnx模型,安装完paddle2onnx后运行  paddle2onnx -m /***/PaddleOCR/ckpts/ch_ppocr_server_v2.0_det_infer/ --model_filename inference.pdmodel --params_filename inference.pdiparams -s /***/ocr/inference_model/onnx/det/model.onnx --opset_version 11 --enable_onnx_checker True  后可得到转化成功的提示:

2021-12-15 16:40:49 [INFO] ONNX model generated is valid.
2021-12-15 16:40:50 [INFO] ONNX model saved in /***/ocr/inference_model/onnx/det/model.onnx

之后检查导出的模型是否成功:

import onnx
import numpy as np
import onnxruntime
onnx_file = '/***/ocr/inference_model/onnx/det/model.onnx'
onnx_model = onnx.load(onnx_file)
onnx.checker.check_model(onnx_model)
print('The model is checked!')
#单步调试到此都没有问题
x = np.random.random((1,3,640,640)).astype('float32')
# predict by ONNX Runtime

#到onnxruntime.InferenceSession下面这句就报错了
ort_sess = onnxruntime.InferenceSession(onnx_file)

ort_inputs = {ort_sess.get_inputs()[0].name: x}
ort_outs = ort_sess.run(None, ort_inputs)
print("Exported model has been predicted by ONNXRuntime!")

报错信息为Traceback (most recent call last):
File "onnx_test.py", line 15, in
ort_sess = onnxruntime.InferenceSession(onnx_file)
File "/**/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 283, in __init__
self._create_inference_session(providers, provider_options, disabled_optimizers)
File "/**/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 310, in _create_inference_session
sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from /***/ocr/inference_model/onnx/det/model.onnx failed:/onnxruntime_src/onnxruntime/core/graph/model.cc:111 onnxruntime::Model::Model(onnx::ModelProto&&, const PathString&, const IOnnxRuntimeOpSchemaRegistryList*, const onnxruntime::logging::Logger&) Unknown model file format version.

主要问题就在onnxruntime调用转化的onnx模型报错Unknown model file format version.请问这种情况怎么解决呀?拜托各位大神指教

0
收藏
回复
全部评论(1)
时间顺序
DeepGeGe
#2 回复于2021-12

这里有个一模一样的问题解决方案,看这个链接:

https://github.com/PaddlePaddle/Paddle2ONNX/issues/329

原因: onnxruntime目前不支持高版本的onnx,导致加载出错
解决方案: 降低环境中onnx的版本至1.6.0~1.9.0 ,重新导出ONNX模型即可

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户