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. |
AIPP supports the following image formats:
YUV420SP_U8
XRGB8888_U8
ARGB8888_U8
YUYV_U8
YUV422SP_U8
AYUV444_U8
YUV400_U8
RGB888_U8
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.
The following AIPP functions are supported, listed in the processing sequence of the chip:
Crop: image cropping.
Channel Swap: channel swapping.
Color Space Conversion: color space conversion.
Resize: image resizing.
Data Type Conversion: data type conversion.
Rotation: image rotation.
Padding: image padding.
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.
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.
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
YUV2BGR

BGR2YUV

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

JPEG

BT-709 narrow

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:
YUV input (YUV420/YUYV/YUV422SP/AYUV444) and RGB model training set (conversion from YUV400 to RGB not supported)
| JPEG | BT-601NARROW | BT-601FULL | BT-709NARROW |
|---|---|---|---|
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 | matrix_r0c0 : 298 matrix_r0c1 : 0 matrix_r0c2 : 409 matrix_r1c0 : 298 matrix_r1c1 : -100 matrix_r1c2 : -208 matrix_r2c0 : 298 matrix_r2c1 : 516 matrix_r2c2 : 0 input_bias_0 : 16 input_bias_1 : 128 input_bias_2 : 128 | 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 | matrix_r0c0 : 298 matrix_r0c1 : 0 matrix_r0c2 : 460 matrix_r1c0 : 298 matrix_r1c1 : -55 matrix_r1c2 : -137 matrix_r2c0 : 298 matrix_r2c1 : 541 matrix_r2c2 : 0 input_bias_0 : 16 input_bias_1 : 128 input_bias_2 : 128 |
YUV input (YUV420/YUYV/YUV422SP/AYUV444) and BGR model training set (conversion from YUV400 to BGR not supported)
| JPEG | BT-601NARROW | BT-601FULL | BT-709NARROW |
|---|---|---|---|
matrix_r0c0 : 256 matrix_r0c1 : 454 matrix_r0c2 : 0 matrix_r1c0 : 256 matrix_r1c1 : -88 matrix_r1c2 : -183 matrix_r2c0 : 256 matrix_r2c1 : 0 matrix_r2c2 : 359 input_bias_0 : 0 input_bias_1 : 128 input_bias_2 : 128 | 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 input_bias_0 : 16 input_bias_1 : 128 input_bias_2 : 128 | matrix_r0c0 : 256 matrix_r0c1 : 454 matrix_r0c2 : 0 matrix_r1c0 : 256 matrix_r1c1 : -88 matrix_r1c2 : -183 matrix_r2c0 : 256 matrix_r2c1 : 0 matrix_r2c2 : 359 input_bias_0 : 0 input_bias_1 : 128 input_bias_2 : 128 | matrix_r0c0 : 298 matrix_r0c1 : 541 matrix_r0c2 : 0 matrix_r1c0 : 298 matrix_r1c1 : -55 matrix_r1c2 : -137 matrix_r2c0 : 298 matrix_r2c1 : 0 matrix_r2c2 : 460 input_bias_0 : 16 input_bias_1 : 128 input_bias_2 : 128 |
YUV input (YUV420/YUYV/YUV422SP/AYUV444) and grayscale (YUV400_U8) model training set
| JPEG | BT-601NARROW | BT-601FULL | BT-709NARROW |
|---|---|---|---|
matrix_r0c0 : 256 matrix_r0c1 : 0 matrix_r0c2 : 0 matrix_r1c0 : 0 matrix_r1c1 : 0 matrix_r1c2 : 0 matrix_r2c0 : 0 matrix_r2c1 : 0 matrix_r2c2 : 0 | N/A | N/A | N/A |
RGB input (XRGB8888/ARGB8888) and grayscale (YUV400_U8) model training set
| JPEG | BT-601NARROW | BT-601FULL | BT-709NARROW |
|---|---|---|---|
matrix_r0c0 : 76 matrix_r0c1 : 150 matrix_r0c2 : 30 matrix_r1c0 : 0 matrix_r1c1 : 0 matrix_r1c2 : 0 matrix_r2c0 : 0 matrix_r2c1 : 0 matrix_r2c2 : 0 | N/A | N/A | N/A |
RGB input (XRGB8888/ARGB8888) and YUV444SP model training set
| JPEG | BT-601NARROW | BT-601FULL | BT-709NARROW |
|---|---|---|---|
matrix_r0c0 : 77 matrix_r0c1 : 150 matrix_r0c2 : 29 matrix_r1c0 : -43 matrix_r1c1 : -85 matrix_r1c2 : 128 matrix_r2c0 : 128 matrix_r2c1 : -107 matrix_r2c2 : -21 output_bias_0 : 0 output_bias_1 : 128 output_bias_2 : 128 | matrix_r0c0 : 66 matrix_r0c1 : 129 matrix_r0c2 : 25 matrix_r1c0 : -38 matrix_r1c1 : -74 matrix_r1c2 : 112 matrix_r2c0 : 112 matrix_r2c1 : -94 matrix_r2c2 : -18 output_bias_0 : 16 output_bias_1 : 128 output_bias_2 : 128 | matrix_r0c0 : 77 matrix_r0c1 : 150 matrix_r0c2 : 29 matrix_r1c0 : -43 matrix_r1c1 : -85 matrix_r1c2 : 128 matrix_r2c0 : 128 matrix_r2c1 : -107 matrix_r2c2 : -21 output_bias_0 : 0 output_bias_1 : 128 output_bias_2 : 128 | matrix_r0c0 : 47 matrix_r0c1 : 157 matrix_r0c2 : 16 matrix_r1c0 : -26 matrix_r1c1 : -87 matrix_r1c2 : 112 matrix_r2c0 : 112 matrix_r2c1 : -102 matrix_r2c2 : -10 output_bias_0 : 16 output_bias_1 : 128 output_bias_2 : 128 |
RGB input (XRGB8888/ARGB8888) and YVU444SP model training set
| JPEG | BT-601NARROW | BT-601FULL | BT-709NARROW |
|---|---|---|---|
matrix_r0c0 : 77 matrix_r0c1 : 150 matrix_r0c2 : 29 matrix_r1c0 : 128 matrix_r1c1 : -107 matrix_r1c2 : -21 matrix_r2c0 : -43 matrix_r2c1 : -85 matrix_r2c2 : 128 output_bias_0 : 0 output_bias_1 : 128 output_bias_2 : 128 | matrix_r0c0 : 66 matrix_r0c1 : 129 matrix_r0c2 : 25 matrix_r1c0 : 112 matrix_r1c1 : -94 matrix_r1c2 : -18 matrix_r2c0 : -38 matrix_r2c1 : -74 matrix_r2c2 : 112 output_bias_0 : 16 output_bias_1 : 128 output_bias_2 : 128 | matrix_r0c0 : 77 matrix_r0c1 : 150 matrix_r0c2 : 29 matrix_r1c0 : 128 matrix_r1c1 : -107 matrix_r1c2 : -21 matrix_r2c0 : -43 matrix_r2c1 : -85 matrix_r2c2 : 128 output_bias_0 : 0 output_bias_1 : 128 output_bias_2 : 128 | matrix_r0c0 : 47 matrix_r0c1 : 157 matrix_r0c2 : 16 matrix_r1c0 : 112 matrix_r1c1 : -102 matrix_r1c2 : -10 matrix_r2c0 : -26 matrix_r2c1 : -87 matrix_r2c2 : 112 output_bias_0 : 16 output_bias_1 : 128 output_bias_2 : 128 |
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.
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.
When the cropping function is disabled, the size of the input image is used as the image size before resizing.
When the cropping function is enabled, as AIPP resizing is always performed after cropping, the size of the image after cropping is used as the size of the image before resizing. During configuration, you only need to pay attention to the size after resizing.
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.
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.
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] |
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.