目录

AIPP Parameters

Static AIPP and dynamic AIPP modes are supported, which are mutually exclusive. Static AIPP models cannot receive AIPP parameters passed during model inference, and are not compatible with dynamic AIPP scenarios. The following table describes the differences between the two AIPP modes.

AIPP How to Set AIPP Parameter Advantage
Static AIPP Pre-defined through the configuration file or IR graph construction during model generation. More efficient: AIPP initialization can be completed in the model loading phase.
Dynamic AIPP The model is only marked with support for AIPP. More flexible: Different sets of AIPP parameters can be passed for each inference.

Supported AIPP Input Formats

AIPP supports the following image formats:

The suffix U8 represents the UINT8 pixel type. The value range is 0–255. When YUV images are input, AIPP pads the image data to the YUV444 format regardless of whether the input format is YUV420, YUV422, or YUYV.

In addition to the preceding image types, AIPP can support more image input formats when channel swapping is enabled.

YUYV_U8 and AYUV444_U8 are not supported in the current version.

AIPP Functions

The following AIPP functions are supported, listed in the processing sequence of the chip:

[h2]Crop

Image cropping in AIPP applies only to input images. The involved parameters are described as follows.

Name Description Value Range
switch Cropping switch. false/true
load_start_pos_w Horizontal coordinate of the cropping start position. load_start_pos_w < src_image_size_w
load_start_pos_h Vertical coordinate of the cropping start position. load_start_pos_h < src_image_size_h
crop_size_w Width of the cropped out image. load_start_pos_w + crop_size_w <= src_image_size_w
crop_size_h Height of the cropped out image. load_start_pos_h + crop_size_h <= src_image_size_h

For YUV420SP, YUYV, YUV422SP, or AYUV444 image input, the coordinates of the cropping start position and the width and height of the cropped out image must be even numbers. Parameter check will be performed accordingly.

[h2]Channel Swap

AIPP supports RB/UV channel swapping and AX channel swapping.

RB/UV channel swapping greatly enriches the input image formats. Once RB/UV channel swapping is enabled, input image formats supported by AIPP are double of the configured input formats.

Configuration Type Image Format
YUV420SP_U8 YUV420, YVU420 + rbuv_swap_switch
XRGB8888_U8 XRGB, XBGR + rbuv_swap_switch
ARGB8888_U8 ARGB, ABGR + rbuv_swap_switch
RGB888_U8 BGR + rbuv_swap_switch
YUYV_U8 YUYV, YVYU + rbuv_swap_switch
YUV422SP_U8 YUV422, YVU422 + rbuv_swap_switch
AYUV444_U8 AYUV + rbuv_swap_switch

AX channel swapping applies to XRGB, ARGB, and AYUV image inputs. Channel swapping moves inputs of the first channel to the fourth channel. That is, with AX channel swapping enabled, XRGB, ARGB, and AYUV data is respectively converted to RGBX, RGBA, and YUVA data.

When the model training set consists of RGB images and the image input for inference is in XRGB or ARGB format, you can enable AX channel swapping to move the RGB channels forward for compatibility.

[h2]Color Space Conversion

Color Space Conversion (CSC) refers to the conversion between the YUV444 and RGB888 image formats. The involved parameters are described as follows.

Name Description Type Value Range
csc_switch CSC switch. bool true/false

matrix_r0c0

matrix_r0c1

matrix_r0c2

matrix_r1c0

matrix_r1c1

matrix_r1c2

matrix_r2c0

matrix_r2c1

matrix_r2c2

CSC matrix elements. int16 [-32677, 32676]

output_bias_0

output_bias_1

output_bias_2

Output biases for RGB2YUV conversion. uint8 [0, 255]

input_bias_0

input_bias_1

input_bias_2

Input biases for YUV2RGB conversion. uint8 [0, 255]

Reference 1: YUV and BGR conversion formulas

Reference 2: BT-601NARROW, JPEG, and BT-709NARROW conversion formulas

To use the configuration file to generate a model with static AIPP, configure the CSC matrix and the value of input_bias or output_bias based on the preceding formulas. To define the AIPP CSC operator in IR mode, or configure the CSC parameters using CANN Kit APIs, pass the target type. The system will fill in the CSC configuration parameters accordingly.

The following describes how to configure the CSC for JPEG and BT-601NARROW images:

From the perspective of usage, it is meaningless to convert grayscale images into RGB images. The system does not support CSC for YUV400_U8 inputs.

[h2]Resize

The image resizing parameters and restrictions are as listed in the following table.

Name Description Value Range (Static) Value Range (Dynamic)
switch Resizing switch. false/true false/true
resize_input_w Image width prior to resizing. [16, 4096] [16, 1280]
resize_input_h Image height prior to resizing. [16, 4096] [16, 4096]
resize_output_w Width of the resized image. [16, 1280] [16, 448]
resize_output_h Height of the resized image. [16, 4096] [16, 4096]

The image resizing ratio and restrictions are as listed in the following table.

Name Description Range (Dynamic & Static)
resize_output_w / resize_input_w Image width resizing ratio. [1/16, 16]
resize_output_h / resize_input_h Image height resizing ratio. [1/16, 16]

The resizing type is bilinear interpolation. The resize_input_w and resize_input_h parameters of the resizing sub-function are invisible to you.

In static AIPP mode, you do not have to configure crop_size_w and crop_size_h (size of the cropped out image) and resize_output_w and resize_output_h (size of the resized image) in the configuration file, if their values can be obtained through computation. If resize_output_w and resize_output_h are omitted, their values are obtained by subtracting padded values from the image size of the model training set. If the resizing function is disabled, crop_size_w and crop_size_h can be omitted.

[h2]Data Type Conversion

Data type conversion (DTC) converts pixel values in input images into the data type used for model training. AIPP allows you to set DTC parameters so that the converted data falls within the expected range. This avoids forcible conversion.

The formula for UINT8 to INT8 conversion is as follows:

pixel_out_chx(i) = pixel_in_chx(i)-mean_chn_i

The formula for UINT8 to FLOAT16 conversion is as follows:

pixel_out_chx(i) = [pixel_in_chx(i)-mean_chn_i-min_chn_i] * var_reci_chn

The following table describes the DTC parameters.

Name Description Value Range
switch DTC switch. false/true
mean_chn_0 Mean value of channel 0. [0, 255]
mean_chn_1 Mean value of channel 1. [0, 255]
mean_chn_2 Mean value of channel 2. [0, 255]
mean_chn_3 Mean value of channel 3. [0, 255]
min_chn_0 Minimum value of channel 0. [-65504, 65504]
min_chn_1 Minimum value of channel 1. [-65504, 65504]
min_chn_2 Minimum value of channel 2. [-65504, 65504]
min_chn_3 Minimum value of channel 3. [-65504, 65504]
var_reci_chn_0 Variance of channel 0. [-65504, 65504]
var_reci_chn_1 Variance of channel 1. [-65504, 65504]
var_reci_chn_2 Variance of channel 2. [-65504, 65504]
var_reci_chn_3 Variance of channel 3. [-65504, 65504]

When the DTC switch is set to false or the DTC parameters are not passed by calling CANN Kit APIs, the system performs forcible conversion on the input images by default, with the mean and minimum values as 0 and the channel variance as 1.

[h2]Rotation

The rotation function of AIPP rotates input images. The involved parameters are described as follows.

Name Description Value Range
switch Rotation switch. false/true
rotation_angle Rotation angle of an image. [0, 90, 180, 270]

[h2]Padding

AIPP padding pads input images. The involved parameters are described as follows.

Name Description Value Range
switch Padding switch. false/true
left_padding_size Padding pixel count on the left side of the image, in pixels. N/A
right_padding_size Padding pixel count on the right side of the image, in pixels. N/A
top_padding_size Padding pixel count on the top side of the image, in pixels. N/A
bottom_padding_size Padding pixel count on the bottom side of the image, in pixels. N/A
padding_value_chn_0 Padding value of channel 0. [-65504, 65504]
padding_value_chn_1 Padding value of channel 1. [-65504, 65504]
padding_value_chn_2 Padding value of channel 2. [-65504, 65504]
padding_value_chn_3 Padding value of channel 3. [-65504, 65504]
  • Keep the AIPP padding sizes within 32 pixels. Too large padding has to be implemented by software code, which is less efficient than hardware-based implementation.

  • Currently, parameters from padding_value_chn_0 to padding_value_chn_3 are not supported.