Home > Mobile >  OpenVINO Model Optimizer transformation of preprocessing the preprocess
OpenVINO Model Optimizer transformation of preprocessing the preprocess

Time:09-28

Depth model at the time of training, in order to get the best reasoning precision, usually will not send the image data (0255) directly, but to do the normalized processing data, such as the data transfer from 8 bit integer (0255) to (0, 1) or (1, 1) of the 32 bit floating point between; For RGB data at the same time, the different framework of reasoning during practice for RGB color channel arrangement/BGR is also different, so the corresponding reasoning, also need the camera caught data also make corresponding pretreatment, do a normalized data, as well as the adjustment of the color channel,



OpenVINO with MO conversion model, also considered the problem, can add some in MO conversion data preprocessing, with the help of the parameters of the corresponding specific practice is in IE runtime in reasoning, at the top of the model, first add a ScaleShift layer to be normalized; For the adjustment of the RGB channel, will add a reorder layer for the exchange of data, so has the advantage of
OpenVINO in achieving ScaleShift calculated automatically when TBB with SIMD instructions or OpenMP for data parallel optimization, through Intel engineer optimized code than our own writing C code implementation efficiency is higher than the don't know a few road
Do with MKLDNN convolution, also need a Reoder to adjust memory data in front of the order, the reorder operation can piggyback RGB< in hand; -> BGR transformation also did, do not need to consume extra time overhead,


Below with Resnet ONNX model, for example, demonstrate how to set the preprocess parameters when MO

First take a look at ONNX Open Model Zoo on Resnet input data and the introduction of preprocessing

This part of the description from the website you can see the input data required is RGB arrangement

The algorithm of normalized data is



RGB three channel scheme, stddev respectively

Mean_vec=np. Array ([0.485, 0.456, 0.406])
Stddev_vec=np. Array ([0.229, 0.224, 0.225])
The corresponding R channel img_data, should be





Corresponding OpenVINO ScaleShift layer scheme and Scale, calculation formula is



Compare the above Resnet ONNX model preprocessing formula



So OpenVINO scheme in the Preprocess of MO/Scale values should be

# Resnet ONNX the preprocess
Mean_vec=np. Array ([0.485, 0.456, 0.406])
Stddev_vec=np. Array ([0.229, 0.224, 0.225])

# OpenVINO
Mean_values=mean_vec * 255
Scale_values=stddev_vec * 255

# mean_value=https://bbs.csdn.net/topics/[123.675, 116.28, 103.53]
# scale_value=https://bbs.csdn.net/topics/[58.395, 57.12, 57.375]
Worked out the scheme/Scale values, then start MO conversion

C: \ Program Files \ (x86) IntelSWTools \ openvino \ deployment_tools \ model_optimizer & gt; Python mo_onnx. Py -- -- input_shape=,3,224,224 [1] - input=data - reverse_input_channels - mean_values=data [123.675, 116.28, 103.53] - scale_values=data [58.395, 57.12, 57.375] -- input_model. \ resnet34 - v2-7. Onnx - o. \
Here in a few parameter

- input_shape=,3,224,224 [1] tell IE runtime input image resolution is 224 x224 3 channel

- reverse_input_channels tell IE put color channel switching when the runtime pretreatment, because what I use is made of OpenCV image processing, image data of BGR arrangement is the default, it is necessary to convert RGB to reasoning

- mean_values=data [123.675, 116.28, 103.53] - scale_values=data [58.395, 57.12, 57.375] calculated in front of the normalized parameter



Finally took a conversion model with accuracy_check precision, the input image, do a 224 x224 scaling, the rest to the reasoning of the runtime to do IE



Results the



Very nice:)
  • Related