Model Building

It is not yet supported to directly run networks trained under open-source frameworks (such as Caffe and TensorFlow) on Ascend AI Processor. ATC is provided 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. Convert the model.

    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. Replace <SAMPLE_DIR> in the following command with the actual directory where the sample package is stored. Replace "<soc_version>" with the actual Ascend AI Processor version.

    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 input data of the model.
    • --soc_version: version of the Ascend AI Processor.

      To check soc_version of a device, perform the following steps:

      • For the following products: Run the npu-smi info command on the server where Ascend AI Processor is installed to obtain the Name information. The actual value is AscendName. For example, if Name is xxxyy, the actual value is Ascendxxxyy.

        Atlas A2 training products/Atlas A2 inference products

        Atlas 200I/500 A2 inference products

        Atlas inference products

        Atlas training products

      • For the following products: Run the npu-smi info -t board -i id -c chip_id command on the server where Ascend AI Processor is installed to obtain the Chip Name and NPU Name information. The actual value is Chip Name_NPU Name. For example, if the value of Chip Name is Ascendxxx and the value of NPU Name is 1234, the actual value is Ascendxxx_1234. Note that:
        • id: device ID, which is the NPU ID obtained by running the npu-smi info -l command.
        • chip_id: chip ID, which is obtained by running the npu-smi info -m command.

        Atlas A3 training products/Atlas A3 inference products

  • 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 graphs, see 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 Ascend AI Processor and call graph build APIs to build your own network, and then compile the network into an .om file. For details, see Graph Mode Development Guide.