Adding Dynamic Dimensions Support to an Offline Model

Overview

To support scenarios such as Transformer using dynamic dimensions, --dynamic_dims allows you to set dynamic dimension profiles in ND format. ND: any format.

Procedure

This section takes the TensorFlow ResNet-50 network model for illustration. Refer to 1 to obtain the original model file.

  1. Log in to the development environment as the CANN running user and upload the model file that supports dynamic dimensions to any directory in the development environment, for example, $HOME/module/.
  2. Include --dynamic_dims in your atc command to generate an offline model (the path and file arguments in the command are for reference only).
    atc --model=$HOME/module/resnet50_tensorflow*.pb --framework=3 --output=$HOME/module/out/tf_resnet50 --soc_version=<soc_version>  --input_shape="Placeholder:-1,-1,-1,3" --dynamic_dims="1,224,224;8,448,448" --input_format=ND 
    For details about the command-line options, see Command Line Options. You should see information similar to the following if the conversion is successful. If it fails, refer to Troubleshooting to locate the fault.
    1
    ATC run success
    

    Find the generated offline model in the path specified by the --output argument.

    In the result .om model, you will find a newly added input, which provides the runtime dimension size for model inference. Assume that the dimensions of input a are dynamic. In the generated OM model, input b is added to describe the dimensions of input a.