openvino踩坑记录——onnx模型转换成IR中间模型

安装openvino
linux系统下按照官网教程安装openvino并进行配置:
https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_linux.html#install-openvino

ONNX模型转换
对于pytorch、tensorflow等框架训练到模型都可以转换成ONNX模型,然后再转换成IR中间模型。
onnx模型转换成IR模型:
1.进入相关目录

cd ~/deployment_tools/model_optimizer

2.转换

python3 mo_onnx.py --input_model <输入模型路经> --output_dir <输出模型路经>

上面的方法能够对onnx model zoo里的模型进行转换。但是如果是自己训练的模型(openvino支持的),则会报错:

 RuntimeWarning: divide by zero encountered in long_scalars
  undefined_dim = num_of_input_elements // num_of_output_elements
[ ERROR ]  Cannot infer shapes or values for node "output/WithoutBiases".
[ ERROR ]  MatMul input shapes are incorrect. COL_INDEX_DIMs are not equal. Node: output/WithoutBiases. Shapes: [array([0, 0]), array([512,  10])]
[ ERROR ]  
[ ERROR ]  It can happen due to bug in custom shape infer function <function MatMul.infer at 0x7f62059e9200>.
[ ERROR ]  Or because the node inputs have incorrect values/shapes.
[ ERROR ]  Or because input shapes are incorrect (embedded to the model or passed via --input_shape).
[ ERROR ]  Run Model Optimizer with --log_level=DEBUG for more information.
[ ERROR ]  Exception occurred during running replacer "REPLACEMENT_ID" (<class 'extensions.middle.PartialInfer.PartialInfer'>): Stopped shape/value propagation at "output/WithoutBiases" node. 

可能是因为input shape未知(所有模型都这样,但只有onnx model zoo能够成功转换),因此将2中代码修改如下:

python3 mo_onnx.py --input_model <输入模型路经> --output_dir <输出模型路经> --input_shape [1,3,32,32](可修改)

最后转换成功。

你可能感兴趣的:(openvino踩坑记录——onnx模型转换成IR中间模型)