如何解决从ONNX运行超级分辨率模型时出错
正在测试super resolution model的ONNX模型,运行this sample program时出错。
我的ONNX版本是1.5.0,带有onnxruntime 1.4.0。 Onnxruntime was installed using pip。 Pytorch版本是1.6.0
错误发生在ort_session = onnxruntime.InferenceSession('/home/itc/pytorch/sub_pixel_cnn_2016/model/super-resolution-10.onnx')
错误在于加载onnx模型。
Traceback (most recent call last):
File "test.py",line 73,in <module>
ort_session = onnxruntime.InferenceSession('/home/itc/pytorch/sub_pixel_cnn_2016/model/super-resolution-10.onnx')
File "/home/itc/pytorch/lib/python3.7/site-packages/onnxruntime/capi/session.py",line 158,in __init__
self._load_model(providers or [])
File "/home/itc/pytorch/lib/python3.7/site-packages/onnxruntime/capi/session.py",line 166,in _load_model
True)
RuntimeError: /onnxruntime_src/onnxruntime/core/session/inference_session.cc:238 onnxruntime::InferenceSession::InferenceSession(const onnxruntime::Sessionoptions&,const onnxruntime::Environment&,const string&) status.IsOK() was false. Given model Could not be parsed while creating inference session. Error message: Protobuf parsing Failed.
解决方法
super-resolution-10.onnx
似乎为我加载了OK。
我从https://github.com/onnx/models/blob/master/vision/super_resolution/sub_pixel_cnn_2016/model/super-resolution-10.onnx
$ pip install onnxruntime
...
Successfully installed onnxruntime-1.5.1
我也尝试过pip install onnxruntime==1.4.0
-也可以。
然后尝试加载它(有很多警告,但可以加载):
In [1]: import onnxruntime
In [2]: onnxruntime.InferenceSession("super-resolution-10.onnx")
2020-10-12 23:25:23.486256465 [W:onnxruntime:,graph.cc:1030 Graph] Initializer conv1.bias appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations,like const folding. Move it out of graph inputs if there is no need to override it,by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-10-12 23:25:23.486293664 [W:onnxruntime:,graph.cc:1030 Graph] Initializer conv1.weight appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations,by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-10-12 23:25:23.486308563 [W:onnxruntime:,graph.cc:1030 Graph] Initializer conv2.bias appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations,by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-10-12 23:25:23.486322663 [W:onnxruntime:,graph.cc:1030 Graph] Initializer conv2.weight appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations,by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-10-12 23:25:23.486335363 [W:onnxruntime:,graph.cc:1030 Graph] Initializer conv3.bias appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations,by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-10-12 23:25:23.486348462 [W:onnxruntime:,graph.cc:1030 Graph] Initializer conv3.weight appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations,by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-10-12 23:25:23.486361862 [W:onnxruntime:,graph.cc:1030 Graph] Initializer conv4.bias appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations,by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
2020-10-12 23:25:23.486384161 [W:onnxruntime:,graph.cc:1030 Graph] Initializer conv4.weight appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations,by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.
Out[2]: <onnxruntime.capi.session.InferenceSession at 0x7f58367236d0>
我认为您的ONNX文件可能已损坏,请尝试将其加载到Netron进行验证。
请注意,PyTorch版本和onnx版本与加载无关。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。