ONNX model to OpenVINO IR model

As different inference backends, ONNX and OpenVINO each have specific advantages, so I won’t repeat them here.

When deploying ONNX or PyTorch models, input images often need to be normalized, channel transformed, etc. before being passed into the network. For the OpenVINO model, the normalization process is moved into the model. In addition, image processing such as BGR to RGB conversion can also be performed in the model without processing the input image.

If the model deployment needs to convert the ONNX model to the OpenVINO IR model, just run the following code in the openvino_{your version}\deployment_tools\model_optimizer folder:

python mo_onnx.py 
--input_shape=[1,3,224,224] 
--input=input 
--mean_values=[103.53,116.28,123.675] 
--scale_values=[57.375,57.12,58.395] 
--data_type FP16 
--input_model "your onnx model path" 
--output_dir "your openvino model folder path"

The input parameters of the onnx model can be viewed with Netron.

There are several points to note when setting parameters:

1. Pay attention to spaces

Note --mean_values=[103.53,116.28,123.675] In this form, there can be no spaces within the square brackets.

You can also use --mean_values="[103.53, 116.28, 123.675]" with spaces.

2. The parameters used for image normalization are:

--mean_values=[103.53,116.28,123.675] 
--scale_values=[57.375,57.12,58.395] 

instead of

--mean_values=[0.406,0.456,0.485] 
--scale_values=[0.225,0.224,0.229] 

参考:Convert a PyTorch Model to ONNX and OpenVINO IR — OpenVINO™ documentation

Guess you like

Origin blog.csdn.net/chan1987818/article/details/126281526