The model inference workflow in the dynamic shape input scenario is similar to that in the scenario described in Developing a Basic Inference App. Both workflows include AscendCL initialization and deinitialization, runtime resource allocation and deallocation, model building, model loading, model execution, and model unloading.
This section focuses on the differences between the two scenarios.
After model building, the inputs of dynamic batch size, dynamic image size, and dynamic dimensions are added to the generated OM model. During model inference, the input values are provided.
Assume that the batch size of input a is dynamic. In the generated OM model, input b is added to describe the batch size of input a. For details about how to prepare the data structure of input a for model execution, see Preparing Input/Output Data Structure for Model Execution. For details about how to prepare the data structure of input b and set the data of input b, see the following description.
#define ACL_DYNAMIC_TENSOR_NAME "ascend_mbatch_shape_data"
Do not initialize the buffer manually; otherwise, the service will be unavailable. After the API calls described in 2, the system automatically initializes the buffer.
The configured batch size must be among the batch size profiles set during model building.
aclmdlGetDynamicBatch can be called to obtain the batch size profiles supported by the model.
The configured image size must be among the image size profiles set during model building.
You can also call the aclmdlGetDynamicHW API to obtain the image size profiles supported by the model.
The configured dimensions must be among the dimension profiles set during model building.
You can also call aclmdlGetInputDynamicDims to obtain the dimension profiles supported by the model.