If the dynamic image size feature is involved during model inference, call the AscendCL API to set the image size. The image size supported by the model has been configured during model building (by using the dynamic_image_size 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 the model and then set the runtime image size.
// ......
//2. Prepare the model description modelDesc_, and the model inputs input_ and model outputs output_.
// ......
//3. Customize a function to set the runtime image size.
int ModelSetDynamicInfo()
{
size_t index;
//3.1 Obtain the indexes of the inputs with dynamic image size. The input name is fixed to ACL_DYNAMIC_TENSOR_NAME.
aclError ret = aclmdlGetInputIndexByName(modelDesc_, ACL_DYNAMIC_TENSOR_NAME, &index);
//3.2 Set the image size. modelId_ indicates the ID of a successfully loaded model, input_ indicates data of type aclmdlDataset, and index indicates the index of the input with dynamic image size.
uint64_t height = 224;
uint64_t width = 224;
ret = aclmdlSetDynamicHWSize(modelId_, input_, index, height, width);
// ......
}
//4. Customize a function to execute the model.
int ModelExecute(int index)
{
aclError ret;
//4.1 Call the user-defined function to set the runtime image size.
ret = ModelSetDynamicInfo();
//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