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:
Following the API calls, add exception handling branches and specify log printing of error and information levels. The following is a code snippet of key steps only, which is not ready to be built or run.
//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 = 2;
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