Model Conversion

The model file generated by the training framework needs to be converted before inference is performed on the Ascend AI Processor. For details about model conversion, see the CANN ATC Instructions.

The following uses TensorFlow YOLOv3 PB as an example to describe how to convert a model into an .om file. The example command is as follows (Atlas 200/300/500 inference product used as an example):
atc --model=./yolov3_tf.pb --framework=3 --output=./yolov3_tf_bs1_fp16 --soc_version=Ascend310 --insert_op_conf=./aipp_yolov3_416_416.aippconfig --input_shape="input/input_data:1,416,416,3" --out_nodes="conv_lbbox/BiasAdd:0;conv_mbbox/BiasAdd:0;conv_sbbox/BiasAdd:0"

out_nodes must be used to specify the output nodes for the YOLOv3 model.

Table 1 Model conversion commands

Command

Description

--framework

Specifies the framework of the model. To specify TensorFlow, set the value to 3.

--soc_version

Specifies the Ascend AI Processor model.

--insert_op_conf

Specifies the configuration file for configuring AIPP (used for image preprocessing, including color space conversion, data normalization, and image cropping). For details, see the CANN ATC Instructions.

--input_shape

Specifies the input size.

--out_nodes

Specifies the output node of the OM.

--model

Specifies the .pb file that needs to be converted.

--output

Specifies the name of the OM file to be exported. The .om file name extension is automatically added.

--output_type

Specifies the data type of the output node. You are advised to set this parameter to FP32 to facilitate the conversion to the float type in model post-processing.

Example aipp.cfg file: (This AIPP file is used to convert the YUV format to the RGB format during color space conversion and is not normalized.)

aipp_op {
aipp_mode: static
input_format : YUV420SP_U8
csc_switch : true
rbuv_swap_switch : false
matrix_r0c0 : 256
matrix_r0c1 : 0
matrix_r0c2 : 359
matrix_r1c0 : 256
matrix_r1c1 : -88
matrix_r1c2 : -183
matrix_r2c0 : 256
matrix_r2c1 : 454
matrix_r2c2 : 0
input_bias_0 : 0
input_bias_1 : 128
input_bias_2 : 128
}