Defining Input/Output Data Types of an Offline Model

Overview

During model conversion, you can specify the data types, formats, and precision modes of the input and output nodes.

For example, the offline model of the TensorFlow ResNet-50 network requires FP16 input, the MaxPoolWithArgmax operator must be specified as the output operator (the corresponding node name is fp32_vars/MaxPoolWithArgmax), and the data type of the output node must be set to FP16. In this scenario, --input_fp16_nodes, --out_nodes, and --output_type allow you to implement those functions.

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 (.pb) used for model conversion to any directory in the development environment, for example, $HOME/module/.
  2. Include --input_fp16_nodes, --out_nodes, and --output_type 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_1.7.pb  --framework=3 --output=$HOME/module/out/tf_resnet50 --soc_version=<soc_version>  --input_fp16_nodes="Placeholder" --out_nodes="fp32_vars/MaxPoolWithArgmax:0" --output_type="fp32_vars/MaxPoolWithArgmax:0:FP16"  
    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 (for example, tf_resnet50.om) in the directory specified by the output argument.

  3. (Optional) If you want to view information about the specified node and data type in the generated offline model, run the following command to convert the offline model into a .json file.
    atc --mode=1 --om=$HOME/module/out/tf_resnet50.om  --json=$HOME/module/out/tf_resnet50.json

    Figure 1 shows that the MaxPoolWithArgmax operator is used as the model output.

    Figure 1 An operator as the output of an offline model