Building a Model

It is not yet supported to directly run networks trained under open-source frameworks (such as ONNX and TensorFlow) on Ascend AI Processor. You need to use ATC to convert such a network into an offline model adapted to the Ascend AI Processor (.om file).

The following uses the ResNet-50 network under the ONNX framework as an example to describe how to use ATC to convert a model. For details, see ATC Instructions.

  1. Log in to the development environment as the running user.
  2. Perform model conversion.

    Run the following command to convert the original model into a *.om model that can be identified by Ascend AI Processor. Note that the running user must have the read and write permissions on the related files specified in the command. In the following command, replace <SAMPLE_DIR> with the actual directory for storing the sample package and replace <soc_version> with the actual version of the .

    cd <SAMPLE_DIR>/MyFirstApp_ONNX/model
    wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/resnet50/resnet50.onnx
    atc --model=resnet50.onnx --framework=5 --output=resnet50 --input_shape="actual_input_1:1,3,224,224"  --soc_version=<soc_version>

    Parameters are listed below. For details about the restrictions, see ATC Instructions.

    • --model: path of the ResNet-50 model file.
    • --framework: source framework type. 5 indicates ONNX.
    • --output: path of the resnet50.om model file. Record this path for future use during app development.
    • --input_shape: shape of the model input.
    • --soc_version: version of Ascend AI Processor.
  3. (Follow-up) If you want to run inference on the generated offline model, prepare the environment, .om file, and input data in .bin format that meets the model input requirements, and then run the msame tool. Click here to obtain the msame tool, and refer to the readme file for instructions.
  • During model conversion, if a message is displayed indicating that some operators are not supported, develop custom operators first by referring to Ascend C Operator Development Guide , and then convert the model again.
  • During model conversion, if a message is displayed, indicating that an operator compilation error occurs, but the message cannot help you locate the error, contact technical support. (After obtaining the logs, click here to contact technical support.) You need to set the DUMP_GE_GRAPH and DUMP_GRAPH_LEVEL environment variables, convert your model again, and collect graphs in each phase during model conversion. For details about the environment variables and graph description, see Dump Graph Details in ATC Instructions.
  • For details about the building and inference of models with a dynamic input shape, see Model Inference with Dynamic-Shape Inputs.
  • If the existing network does not meet your requirements, you can use the operators supported by and call Ascend Graph APIs to build your own network, and then compile the network into an .om file. For details, see Ascend Graph Developer Guide.