If the dynamic AIPP feature is involved during model inference, call the AscendCL API to set the AIPP parameters. The AIPP parameters supported by the model have been configured during model building (by using the insert_op_conf parameter of ATC).
For details about the ATC parameter, see ATC Instructions.
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.
size_t index;
//modelDesc_ is of type aclmdlCreateDesc for the model description, which is obtained based on the ID of the model that is successfully loaded in step 1.
aclError ret = aclmdlGetInputIndexByName(modelDesc_, ACL_DYNAMIC_AIPP_NAME, &index);
//3.2 Set dynamic AIPP attributes.
uint64_t batchNumber = 1;
aclmdlAIPP *aippDynamicSet = aclmdlCreateAIPP(batchNumber);
ret = aclmdlSetAIPPSrcImageSize(aippDynamicSet, 256, 224);
ret = aclmdlSetAIPPInputFormat(aippDynamicSet, ACL_YUV420SP_U8);
ret = aclmdlSetAIPPCscParams(aippDynamicSet, 1, 256, 443, 0, 256, -86, -178, 256, 0, 350, 0, 0, 0, 0, 128, 128);
ret = aclmdlSetAIPPRbuvSwapSwitch(aippDynamicSet, 0);
ret = aclmdlSetAIPPDtcPixelMean(aippDynamicSet, 0, 0, 0, 0, 0);
ret = aclmdlSetAIPPDtcPixelMin(aippDynamicSet, 0, 0, 0, 0, 0);
ret = aclmdlSetAIPPPixelVarReci(aippDynamicSet, 1.0, 1.0, 1.0, 1.0, 0);
ret = aclmdlSetAIPPCropParams(aippDynamicSet, 1, 2, 2, 224, 224, 0);
ret = aclmdlSetInputAIPP(modelId_, input_, index, aippDynamicSet);
ret = aclmdlDestroyAIPP(aippDynamicSet);
// ......
}
//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