Dynamic AIPP (Multiple Dynamic AIPP Inputs)

This section describes the key APIs and sample code for model inference with multiple dynamic AIPP inputs.

API Call Sequence

Dynamic AIPP (Single Dynamic AIPP Input) describes the workflow of model inference with a single dynamic AIPP input.

When your model has more than one dynamic AIPP input, the inference workflow shows some slight changes:

  • Call aclmdlGetAippType to check whether the specified model input is associated with a dynamic AIPP input. If yes, the call returns the index of the dynamic AIPP input, which can be passed to the aclmdlSetAIPPByInputIndex call to set the dynamic AIPP attributes.
  • To avoid setting dynamic AIPP attributes on a wrong input, you can call aclmdlGetInputNameByIndex to obtain the input name of the specified index and then set dynamic AIPP attributes by input index.

Sample Code

After APIs are called, you need to add exception handling branches and record error logs and info logs. The following is a code snippet of key steps only, which is not ready to be built or run.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//1. Load a model and then set dynamic AIPP attributes.
// ......

//2. Prepare the model description modelDesc_, and the model inputs input_ and model outputs output_.
// ......

//3. Call the user-defined function to set the dynamic AIPP attributes.
int  ModelSetDynamicAIPP()
{
    //3.1 Obtain the index of the dynamic AIPP input.
    std::vector<size_t> dataNeedDynamicAipp;
    for (size_t index = 0; index < aclmdlGetNumInputs(modelDesc_); ++index) {
        aclmdlInputAippType aippType;
        size_t dynamicAttachedDataIndex;
        aclError ret = aclmdlGetAippType(modelId_, index, &aippType, &dynamicAttachedDataIndex);
        if (aippType == ACL_DATA_WITH_DYNAMIC_AIPP) {
            dataNeedDynamicAipp.push_back(index);
        }
    }

    //3.2 In this example, two dynamic AIPP inputs are used.
    if (dataNeedDynamicAipp.size() != 2) {
        return -1;
    }
    //Create the first dynamic AIPP configuration.
    uint64_t batchNumber1 = 1;
    aclmdlAIPP *aippDynamicSet1 = aclmdlCreateAIPP(batchNumber1);
    ret = aclmdlSetAIPPSrcImageSize(aippDynamicSet1, 256, 224);
    ret = aclmdlSetAIPPInputFormat(aippDynamicSet1, ACL_YUV420SP_U8);
    ret = aclmdlSetAIPPCscParams(aippDynamicSet1, 1, 256, 443, 0, 256, -86, -178, 256, 0, 350, 0, 0, 0, 0, 128, 128);
    ret = aclmdlSetAIPPRbuvSwapSwitch(aippDynamicSet1, 0);
    ret = aclmdlSetAIPPDtcPixelMean(aippDynamicSet1, 0, 0, 0, 0, 0);
    ret = aclmdlSetAIPPDtcPixelMin(aippDynamicSet1, 0, 0, 0, 0, 0);
    ret = aclmdlSetAIPPPixelVarReci(aippDynamicSet1, 1.0, 1.0, 1.0, 1.0, 0);
    ret = aclmdlSetAIPPCropParams(aippDynamicSet1, 1, 2, 2, 224, 224, 0);
   //Set the dynamic AIPP attributes.
    ret = aclmdlSetAIPPByInputIndex(modelId_, input_, dataNeedDynamicAipp[0], aippDynamicSet1);
    ret = aclmdlDestroyAIPP(aippDynamicSet1);

   //Create the second dynamic AIPP configuration.
    uint64_t batchNumber2 = 1;
    aclmdlAIPP *aippDynamicSet2 = aclmdlCreateAIPP(batchNumber2);
    ret = aclmdlSetAIPPSrcImageSize(aippDynamicSet2, 224, 224);
   //Call more AIPP configuration setting APIs as needed.
   //Set the dynamic AIPP attributes.
    ret = aclmdlSetAIPPByInputIndex(modelId_, input_, dataNeedDynamicAipp[1], aippDynamicSet2);
    ret = aclmdlDestroyAIPP(aippDynamicSet2);
}

//4. Customize a function to execute the model.
int ModelExecute(int index)
{
        aclError ret;
        //4.1 Call the user-defined function to set the dynamic AIPP attributes.
	ret = ModelSetDynamicAIPP();
        //4.2 Execute the model. modelId_ indicates the ID of a successfully loaded model, input_ indicates the model inputs, and output_ indicates the model outputs.
        ret = aclmdlExecute(modelId_, input_, output_);
        // ......
}

//5. Process the model inference result.
// TODO