#python #onnx #onnxruntime
#python #onnx #onnxruntime
Вопрос:
Тестирование модели ONNX для модели с высоким разрешением, у меня ошибка при запуске этого примера программы.
Моя версия ONNX 1.5.0 с onnxruntime 1.4.0. Onnxruntime был установлен с помощью 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::SessionOptionsamp;, const onnxruntime::Environmentamp;, const stringamp;) status.IsOK() was false. Given model could not be parsed while creating inference session. Error message: Protobuf parsing failed.
Как я могу устранить ошибку?
Комментарии:
1. На всякий случай, можете ли вы убедиться, что ваш файл super-resolution-10.onnx может быть загружен с помощью Netron, чтобы убедиться, что файл не поврежден.
2. Перекрестная ссылка на проблему с github github.com/onnx/models/issues/385
Ответ №1:
super-resolution-10.onnx
кажется, для меня все в порядке. Я скачал файл с 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, 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.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, 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.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, 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.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, 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.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, 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.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, 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.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, 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.
Out[2]: <onnxruntime.capi.session.InferenceSession at 0x7f58367236d0>
Я думаю, что, вероятно, ваш файл ONNX поврежден, пожалуйста, попробуйте загрузить его с помощью Netron для проверки.
В качестве примечания, версия PyTorch и версия onnx не должны иметь значения для загрузки.
Комментарии:
1. Спасибо. Да, модель загружена по этой ссылке ( github.com/onnx/models ) был поврежден. Я загрузил целые папки моделей, и модель с высоким разрешением внутри не может отображаться с помощью Netron. Предоставленная вами ссылка имеет хорошую модель. Netron может отображать модель. На самом деле они одинаковы. Загружена вся папка, и модель внутри повреждена.