Configuration File Template
The AIPP configuration file is configured using the template provided in this section, and its content must be in .prototxt format. You can determine which parameters to configure based on specific scenarios, and change them to appropriate values before saving them for model conversion. Prior to using the configuration template, check related restrictions first.
General Restrictions
- To use this configuration file, uncomment necessary parameters and set them to appropriate values.
- The parameter values in the template are default values. If a parameter in your configuration file is not specified, its default value will be used during model conversion.
- In static AIPP mode, only the input_format parameter is required, while the rest is optional. If these parameters are not specified, their default values will be used during model conversion.
- Restricted by hardware processing logic, AIPP functions will be processed in the following sequence: channel swap (rbuv_swap_switch) -> cropping -> CSC -> mean subtraction/normalization -> padding.
- AIPP supports the following features: CSC, cropping, mean subtraction, factor multiplication, channel swapping, and single-line mode. Only RAW and UINT8 input images are supported.
- If the input image is in RGB format, the sequence of the input and output channels is {R, G, B} from high address to low address.
- In dynamic AIPP mode, parameters are computed for each inference, which is time consuming. Therefore, dynamic AIPP delivers poorer performance than static AIPP.
- The images processed by AIPP are stored in the 5D format NC1HWC0.
The following uses an RGB image as an example to describe how to configure the AIPP function:
- For Caffe and ONNX, the data format can only be NCHW (the data format is RRRRRRGGGGGGBBBBBB).
- For TensorFlow, the data format can be NHWC (the data format is RGBRGBRGBRGBRGBRGB) or NCHW (the data format is RRRRRRGGGGGGBBBBBB).
After AIPP CSC, the output image in the offline model is in RGB format and stored in the 5D data format NC1HWC0. For details about NC1HWC0, see Terminology. If the data type of the AIPP output is FP16, C0 equals 16. R, G, and B components are arranged from upper bits to lower bits. Other bits are padded with 0s. Additionally, C1 equals 1.
- Depending on whether AIPP is enabled during model conversion, the requirements on the input image for model inference are as follows:
- AIPP enabled during model conversion: The input image should be in NHWC format for model inference, possibly resulting in a format inconsistent with that specified by --input_format in the model conversion command.
- AIPP disabled during model conversion: The format of the model must be the same as that of the input image during inference. For example, if the format of the input image is NHWC but the default format of a model is NCHW, you can specify --input_format during model conversion to adjust the model format or select another input image with the consistent format.
- For input images in YUV420SP format, YUV420SP is classified into YUV420SP_UV(NV12) and YUV420SP_VU(NV21) based on the UV component sequence, corresponding to YUV420SP_U8 and YVU420SP_U8 in CSC Configuration, respectively. The default format is YUV420SP_UV(NV12).The input_format parameter in the AIPP configuration file must be always set to the NV12 format (YUV420SP_U8). The rbuv_swap_switch parameter is used to determine the format of the image provided for AIPP.
- If rbuv_swap_switch is set to false, the image format is YUV420SP_U8.
- If rbuv_swap_switch is set to true, the image format is YVU420SP_U8.
- Restrictions on the C-axis values corresponding to different AIPP image formats.
Table 1 C-axis values corresponding to different image formats AIPP Input Format
C-Axis Value
YUV420SP_U8
C=1
RGB888_U8
C=3
XRGB8888_U8
C=4
YUV400_U8
C=1
- The following table describes the typical parameter settings of AIPP for various image formats.
Configuration File Template
# The AIPP configuration starts with the aipp_op flag, which indicates that it is the configuration of an AIPP operator. Multiple aipp_op flags can be configured.
aipp_op {
#========================= Global settings (start) ===========================================================================================================================================================
# aipp_mode (required) specifies the AIPP mode.
# Type: enum
# Value range: dynamic or static
aipp_mode:
# related_input_rank (optional) indicates the sequence number of the input to be processed by AIPP. The default value 0 indicates that the processing starts from input 0. If the model has two inputs, to start processing from the second, set related_input_rank to 1.
# Type: int
# Value range: >= 0
related_input_rank: 0
# related_input_name (optional) indicates the name of the model input (value of input) for AIPP processing, or the output (value of top) of the first-layer node. This parameter applies only to Caffe networks and is mutually exclusive with related_input_rank. If they are configured at the same time, related_input_name takes precedence over related_input_rank.
# If the model has two inputs such as data and im_info, to start processing from the second, set related_input_name to im_info.
# Type: string
# Type: string
related_input_name: ""
#========================= Global settings (end) =============================================================================================================================================================
#========================= Dynamic AIPP settings (start) ===================================================================================================================================
# The maximum size of the input image must be configured in dynamic AIPP. (In the dynamic batch scenario, N is set to the maximum in batch size.)
# Type: int
max_src_image_size: 0
# If the input image format is YUV400_U8, max_src_image_size >= N x src_image_size_w x src_image_size_h x 1.
# If the input image format is YUV420SP_U8, max_src_image_size >= N x src_image_size_w x src_image_size_h x 1.5.
# If the input image format is XRGB8888_U8, max_src_image_size >= N x src_image_size_w x src_image_size_h x 4.
# If the input image format is RGB888_U8, max_src_image_size >= N x src_image_size_w x src_image_size_h x 3.
# Rotation switch. This parameter is reserved. Rotation is not supported currently.
# Type: bool
# Value range: true (enabled) or false (disabled)
support_rotation: false
#========================= Dynamic AIPP settings (end) =======================================================================================================================================
#========================= Static AIPP settings (start) ======================================================================================================================================
# (Required) Input image format
# Type: enum
# Value range: YUV420SP_U8, XRGB8888_U8, RGB888_U8, and YUV400_U8
input_format:
# Note: After your model is converted, you will see these parameters represented as enum values 1, 2, 3, 4 in the corresponding *.om model file.
# Width and height of the source image
# Type: int32
# Value range & constraint: The ranges of width and height are [2, 4096] or 0, and [1, 4096] or 0, respectively. For YUV420SP_U8 images, the values must be even numbers.
src_image_size_w: 0
src_image_size_h: 0
# Note: Set src_image_size_w and src_image_size_h to the actual image width and height. If cropping is disabled and padding settings are not configured, they can be set to 0 or not configured. In this case, the values of width and height are obtained from those defined in the network model, with a width and height in the ranges of [2, 4096] and [1, 4096], respectively.
# Padding value for the C dimension. This parameter is reserved. Padding is not supported currently.
# Type: float16
# Value range: [–65504, +65504]
cpadding_value: 0.0
#========= Crop settings (For the configuration example, see section "AIPP Configuration" > "Crop/Padding Configuration".) =========
# Cropping switch
# Type: bool
# Value range: true (enabled) or false (disabled)
crop: false
# Start coordinates of the cropping area. W and H defined in the network input are used as the size of the cropped image.
# Type: int32
# Value range & constraint: [0, 4095].
# For YUV420SP_U8 images, the values must be even numbers if the Atlas 200/300/500 Inference Product , or Atlas Training Series Product is used. There is no such requirement if other chips are used.
# Note: load_start_pos_w < src_image_size_w, load_start_pos_h < src_image_size_h
load_start_pos_w: 0
load_start_pos_h: 0
# Size of the cropped image
# Type: int32
# Value range & constraint: [0, 4096]. load_start_pos_w + crop_size_w ≤ src_image_size_w, and load_start_pos_h + crop_size_h ≤ src_image_size_h.
crop_size_w: 0
crop_size_h: 0
Note: If the image cropping function is enabled and and padding settings are not configured, crop_size_w and crop_size_h can be set to 0 or not configured. In this case, the cropped width and height (crop_size[W|H]) are obtained from --input_shape in the model file with a value range [1, 4096].
# The following conditions must be met:
# If input_format = YUV420SP_U8, the values of load_start_pos_w and load_start_pos_h must be even numbers when the Atlas 200/300/500 Inference Product , or Atlas Training Series Product is used. There is no such requirement when other chips are used.
# If input_format is set to other values, there is no restriction on , load_start_pos_w and load_start_pos_h.
# If cropping is enabled, the following condition must be met: src_image_size[W|H] >= crop_size[W|H] + load_start_pos[W|H]
#================================== Resize settings ================================
# Resizing switch. This parameter is reserved. Resizing is not supported currently.
# Type: bool
# Value range: true (enabled) or false (disabled)
resize: false
# Width and height of the resized image. This parameter is reserved. Resizing is not supported currently.
# Type: int32
# Value range & constraint: resize_output_h ∈ [16, 4096] or 0; resize_output_w ∈ [16, 1920] or 0; resize_output_w and resize_input_w ∈ [1/16, 16], resize_output_h and resize_input_h ∈ [1/16, 16]
resize_output_w: 0
resize_output_h: 0
# Note: If the resizing function is enabled and padding settings are not configured, resize_output_w and resize_output_h can be set to 0 or not configured. In this case, the width and height of the resized image are obtained from those in the --input_shape in the model file, with a height and width in the ranges of [16, 4096] and [16, 1920] respectively.
#========= Padding settings (For the configuration example, see section "AIPP Configuration" > "Crop/Padding Configuration".) =========
# Padding switch
# Type: bool
# Value range: true (enabled) or false (disabled)
padding: false
# Padding values of H and W, configured in static AIPP mode
# Type: int32
# Value range: [0, 32]
left_padding_size: 0
right_padding_size: 0
top_padding_size: 0
bottom_padding_size: 0
# Note: After AIPP padding, the output H and W must be the same as those required by the model.
# For the Atlas 200/300/500 Inference Product , and Atlas Training Series Product , W ≤ 1080
# Top, bottom, left, and right padding values, configured in static AIPP mode
# Type: uint8, int8, or float16
# Value range: [0, 255], [–128, +127], or [–65504, +65504]
padding_value: 0
# Note: The data type of this value must be identical to that of the AIPP output.
#================================ Rotation settings ==================================
# Rotation angle. This parameter is reserved. Rotation is not supported currently.
# Type: uint8
# Value range: {0, 1, 2, 3}, where 0: rotation disabled, 1: 90° clockwise rotation, 2: 180° clockwise rotation, and 3: 270° clockwise rotation.
rotation_angle: 0
#========= CSC settings (For the configuration example, see section "AIPP Configuration" > "CSC Configuration".) =============
# CSC switch, configured in static AIPP mode
# Type: bool
# Value range: true (enabled) or false (disabled)
csc_switch: false
# R/B or U/V channel swap switch
# Type: bool
# Value range: true (enabled) or false (disabled)
rbuv_swap_switch :false
# RGBA->ARGB and YUVA->AYUV swap switch
# Type: bool
# Value range: true (enabled) or false (disabled)
ax_swap_switch: false
# Single-line processing switch (only the first line after image cropping). This parameter is reserved. This function is not supported currently.
# Type: bool
# Value range: true (enabled) or false (disabled)
single_line_mode: false
# If CSC is disabled (false), this function does not take effect.
# If the input image has 4 channels, channel A or X is ignored.
# YUV2BGR conversion:
# | B | | matrix_r0c0 matrix_r0c1 matrix_r0c2 | | Y - input_bias_0 |
# | G | = | matrix_r1c0 matrix_r1c1 matrix_r1c2 | | U - input_bias_1 | >> 8
# | R | | matrix_r2c0 matrix_r2c1 matrix_r2c2 | | V - input_bias_2 |
# BGR2YUV conversion:
# | Y | | matrix_r0c0 matrix_r0c1 matrix_r0c2 | | B | | output_bias_0 |
# | U | = | matrix_r1c0 matrix_r1c1 matrix_r1c2 | | G | >> 8 + | output_bias_1 |
# | V | | matrix_r2c0 matrix_r2c1 matrix_r2c2 | | R | | output_bias_2 |
# Elements in the 3 x 3 CSC matrix
# Type: int16
# Value range: [–32677, +32676]
matrix_r0c0: 298
matrix_r0c1: 516
matrix_r0c2: 0
matrix_r1c0: 298
matrix_r1c1: -100
matrix_r1c2: -208
matrix_r2c0: 298
matrix_r2c1: 0
matrix_r2c2: 409
# Output biases for RGB2YUV conversion
# Type: uint8
# Value range: [0, 255]
output_bias_0: 16
output_bias_1: 128
output_bias_2: 128
# Input biases for YUV2RGB conversion
# Type: uint8
# Value range: [0, 255]
input_bias_0: 16
input_bias_1: 128
input_bias_2: 128
#============================== Mean subtraction and factor multiplication settings =================================
# The computation rules are as follows.
# When uint8->uint8, this function does not take effect.
# For uint8->fp16: pixel_out_chx(i) = [pixel_in_chx(i) – mean_chn_i – min_chn_i] x var_reci_chn_i
# Mean value of each channel
# Type: uint8
# Value range: [0, 255]
mean_chn_0: 0
mean_chn_1: 0
mean_chn_2: 0
mean_chn_3: 0
# Minimum value of each channel
# Type: float16
# Value range: [0, 255]
min_chn_0: 0.0
min_chn_1: 0.0
min_chn_2: 0.0
min_chn_3: 0.0
# Reciprocal of the variance of each channel
# Type: float16
# Value range: [–65504, +65504]
var_reci_chn_0: 1.0
var_reci_chn_1: 1.0
var_reci_chn_2: 1.0
var_reci_chn_3: 1.0
#========================= Static AIPP settings (end) =====================================================================================================================================
}