Rate and give feedback:
Huawei uses machine translation combined with human proofreading to translate this document to different languages in order to help you better understand the content of this document.
Note: Even the most advanced machine translation cannot match the quality of professional translators.
Huawei shall not bear any responsibility for translation accuracy and it is recommended that you refer to the English document (a link for which has been provided).
Dynamic Image Size
If the image size processed at a time during model inference is not fixed, you can set different image sizes during IR graph construction as follows:
- During Data operator definition, set the H and W dimensions in the data shape to –1.
auto shape_data = vector<int64_t>({ 8,3,–1,–1 }); TensorDesc desc_data(ge::Shape(shape_data), FORMAT_ND, DT_FLOAT); auto data = op::Data("data"); data.update_input_desc_data(desc_data); data.update_output_desc_out(desc_data);
- During model building, in the options argument passed to the aclgrphBuildModel call, set INPUT_SHAPE to be the same as that of the Data node and specify the dynamic image size choices by setting DYNAMIC_IMAGE_SIZE.
void PrepareOptions(std::map<std::string, std::string>& options) { options.insert({ {ge::ir_option::EXEC_DISABLE_REUSED_MEMORY, "1"}, // Disable memory overcommitment. {ge::ir_option::INPUT_SHAPE, "data: 8,3,-1,-1"}, // Specify the input shape as {8,3,–1,–1}. {ge::ir_option::DYNAMIC_IMAGE_SIZE, "416,416;832,832"} // Set the H and W dimensions. This setting indicates that 416 x 416 and 832 x 832 images are supported. }); }
Other description of this function:
- Dynamic batch size and dynamic image size are mutually exclusive, that is, they cannot be both set.
- A maximum of 100 image size choices are supported. Separate the image size choices by semicolon (;). If an image size choice, or the number of image size choices is set too large, model build may fail.
- If dynamic image size is set during model building, before calling aclmdlExecute for model inference, aclmdlSetDynamicHWSize needs to be called for setting the actual image size. In addition, the size of the dataset images used for model inference must be the same as the image size that is used. For details about the aclmdlSetDynamicHWSize API, see Application Software Development Guide.