Function: set_input_aipp

C Prototype

aclError aclmdlSetInputAIPP(uint32_t modelId, aclmdlDataset *dataset, size_t index, const aclmdlAIPP *aippParmsSet)

Python Function

ret = acl.mdl.set_input_aipp(model_id, dataset, index, aipp_parms_set)

Function Usage

Sets the AIPP attributes for model inference based on the index of the dynamic AIPP input in the dynamic AIPP scenario.

Dynamic AIPP provides the following operations and they are executed in the exact sequence:

  1. Cropping
  2. Color space conversion
  3. Resizing (not supported in the current version)
  4. Mean subtraction/Normalization
  5. Padding

Input Description

model_id: int, model ID.

You can obtain the model ID after the model is successfully loaded by calling the following APIs:

dataset: int, pointer address of a model's input data. Data of type aclmdlDataset describes the input data for model inference, while data of type aclDataBuffer describes the input buffer size and address.

index: int, input index of the dynamic AIPP input.

  • When the model has more than one dynamic AIPP input, you can call acl.mdl.get_aipp_type to obtain the specified input index.
  • To ensure forward compatibility, if there is only one dynamic AIPP input, you can call acl.mdl.get_input_index_by_name to obtain the input index. The input name is fixed to ascend_dynamic_aipp_data.

aipp_parms_set: int, pointer address of the dynamic AIPP configuration object. The aclmdlAIPP data must be created by calling acl.mdl.create_aipp in advance.

Return Value

ret: int, error code.

Restrictions

  • The image size after dynamic AIPP processing must be the same as that defined by the input shape required by the original model.
  • In batched inference scenarios, the image size after dynamic AIPP is calculated based on the configuration of each batch. After dynamic AIPP, the output image size must be consistent across batches. Table 1 describes the formulas for calculating the result image size.
  • After image cropping, resizing, or padding, the rules for verifying the image size after dynamic AIPP are as follows. aippOutputW and aippOutputH indicate the width and height of the AIPP output image, respectively. Other parameters are the input parameters of the acl.mdl.set_aipp_src_image_size, acl.mdl.set_aipp_crop_params, and acl.mdl.set_aipp_padding_params APIs.

Reference

For details about the API call sequence and example, see Dynamic AIPP (Single Dynamic AIPP Input).

Table 1 Formulas for calculating the output image size

Cropping

Resizing

Padding

Output Width and Height

No

No

No

aippOutputW = srcImageSizeW

aippOutputH = srcImageSizeH

Yes

No

No

aippOutputW = cropSizeW

aippOutputH = cropSizeH

Yes

Yes

No

aippOutputW = scfOutputSizeW

aippOutputH = scfOutputSizeH

Yes

No

Yes

aippOutputW = cropSizeW + paddingSizeLeft + paddingSizeRight

aippOutputH = cropSizeH + paddingSizeTop + paddingSizeBottom

No

No

Yes

aippOutputW = srcImageSizeW + paddingSizeLeft + paddingSizeRight

aippOutputH = srcImageSizeH + paddingSizeTop + paddingSizeBottom

No

Yes

Yes

aippOutputW = scfOutputSizeW + paddingSizeLeft + paddingSizeRight

aippOutputH = scfOutputSizeH + paddingSizeTop + paddingSizeBottom

No

Yes

No

aippOutputW = scfOutputSizeW

aippOutputH = scfOutputSizeH

Yes

Yes

Yes

aippOutputW = scfOutputSizeW + paddingSizeLeft + paddingSizeRight

aippOutputH = scfOutputSizeH + paddingSizeTop + paddingSizeBottom