Getting Started

This chapter describes how to quickly convert an offline model on different frameworks by using samples.

  • Version compatibility:
    • For 8.5.0 and later versions: When using the ATC tool for model conversion, you must install the ops operator package that matches the target Ascend AI Processor. Otherwise, the build will fail.
    • An offline model converted from the CANN package of an earlier version can run in the CANN package of a later version and is compatible with four version periods.
  • If it takes too long to convert a model in the Arm (AArch64) development environment, fix it by referring to What Do I Do If Model Conversion Takes Too Long When the Development Environment Architecture Is Arm (AArch64)?
  • If you use network model accuracy option --precision_mode or --precision_mode_v2 during model conversion:
    • For both options, performance takes priority for the default value and accuracy overflow issues may occur during subsequent inference. If an accuracy issue occurs during inference, locate the fault by referring to ""Accuracy Improvement Suggestions for Model Inference"".
    • If you want to avoid accuracy issues, you can set both options to values other than the default ones. For example, you can set --precision_mode to must_keep_origin_dtype or set --precision_mode_v2 to origin.

Converting an Open-Source TensorFlow Model to an Offline Model

  1. Obtain a TensorFlow model.

    Click here to download the *.pb model file of the ResNet-50 network and upload the file to any directory in the development environment as the CANN running user, for example, $HOME/module/.

  2. Run the following command to generate an offline model. (The path and file options 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>   
    • --model: specifies the path of the ResNet50 model file.
    • --framework: specifies the original framework type. The value 3 indicates TensorFlow.
    • --output: specifies the path for storing the generated offline model.
    • --soc_version: specifies the Ascend AI Processor version.

    For details about the command-line options, see Command Line Options. Set <soc_version> to the actual SoC name for model conversion before running inference. Refer to --soc_version to query the SoC details.

  3. Check that your model is converted successfully.
    1
    ATC run success, welcome to the next use.
    

    Find the generated offline model (for example, tf_resnet50.om) in the directory specified by the --output argument. If the model conversion fails, locate the fault by referring to "Error Codes".

Converting an ONNX Model to an Offline Model

  1. Obtain an ONNX model.

    Click here to go to the ModelZoo page and obtain the .onnx model file by referring to "Getting Started > Model Inference" in README.md. Then upload the model file to any directory (for example, $HOME/module/) of the development environment as the CANN running user.

  2. Run the following command to generate an offline model. (The path and file options in the command are for reference only.)
    atc --model=$HOME/module/resnet50*.onnx --framework=5 --output=$HOME/module/out/onnx_resnet50 --soc_version=<soc_version>  
    • --model: specifies the path of the ResNet-50 model file.
    • --framework: specifies the original framework type. The value 5 indicates ONNX.
    • --output: specifies the path for storing the generated offline model.
    • --soc_version: specifies the Ascend AI Processor version.

    For details about the command-line options, see Command Line Options. Set <soc_version> to the actual SoC name for model conversion before running inference. Refer to --soc_version to query the SoC details.

  3. Check that your model is converted successfully.
    1
    ATC run success, welcome to the next use.
    

    Find the generated offline model (for example, onnx_resnet50.om) in the path specified by the --output argument. If the model conversion fails, locate the fault by referring to "Error Codes".

Converting an Open-Source Caffe Model to an Offline Model

  1. Obtain a Caffe network model.

    Download the .prototxt model file and .caffemodel weight file of the ResNet-50 network and upload the files to any directory in the development environment as the CANN running user, for example, $HOME/module/.

    • ResNet-50 network model file (*.prototxt): Click here to download the file.
    • ResNet-50 weight file (*.caffemodel): Click here to download the file.
  2. Run the following command to generate an offline model. (The path and file options in the command are for reference only.)
    atc --model=$HOME/module/resnet50.prototxt --weight=$HOME/module/resnet50.caffemodel --framework=0 --output=$HOME/module/out/caffe_resnet50 --soc_version=<soc_version>  
    • --model: specifies the path of the ResNet-50 model file.
    • --weight: specifies the path of the ResNet-50 weight file.
    • --framework: specifies the original framework type. The value 0 indicates Caffe.
    • --output: specifies the path for storing the generated offline model.
    • --soc_version: specifies the Ascend AI Processor version.

    For details about the command-line options, see Command Line Options. Set <soc_version> to the actual SoC name for model conversion before running inference. Refer to --soc_version to query the SoC details.

  3. Check that your model is converted successfully.
    1
    ATC run success, welcome to the next use.
    

    Find the generated offline model (for example, caffe_resnet50.om) in the path specified by the --output argument. If the model conversion fails, locate the fault by referring to "Error Codes".

Converting an .air Model File to an Offline Model

  1. Obtain an .air model file.

    Click here to download the ResNet-50 model file and upload the file to any path in the development environment as the CANN running user, for example, $HOME/module/.

  2. Run the following command to generate an offline model. (The path and file options in the command are for reference only.)
    atc --model=$HOME/module/ResNet50.air --framework=1 --output=$HOME/module/out/ResNet50_air --soc_version=<soc_version>
    • --model: specifies the path of the .air model file.
    • --framework: specifies the original framework type. The value 1 indicates the .air model file.
    • --output: specifies the path for storing the generated offline model.
    • --soc_version: specifies the Ascend AI Processor version.

    For details about the command-line options, see Command Line Options. Set <soc_version> to the actual SoC name for model conversion before running inference. Refer to --soc_version to query the SoC details.

  3. Check that your model is converted successfully.
    1
    ATC run success, welcome to the next use.
    

    Find the generated offline model (for example, ResNet50_air.om) in the path specified by the --output option. If the model conversion fails, locate the fault by referring to "Error Codes".