ONNX Model Conversion Using ATC Commands
This section describes how to use ATC commands to automatically convert an .onnx model file and execute the model on Ascend AI Processor in graph mode.
The GE provides the model conversion capability for model files exported from front-end frameworks such as PyTorch, TensorFlow, and MindSpore. You can use the ATC command line tool to convert the model files into offline models that adapt to Ascend AI Processor, and to execute the models in graph mode. Currently, ATC supports the following conversions:
- From *.onnx to *.om
- From *.pb to *.om
- From *.air to *.om
- From *.prototxt and *.caffemodel to *.om
The following uses the conversion from *.onnx to *.om as an example to describe the basic usage method.
- Obtain an ONNX network 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.
- Use the ATC command line tool to convert a model (for example, .onnx).
atc --model=$HOME/module/resnet50*.onnx --framework=5 --output=$HOME/module/out/onnx_resnet50 --soc_version=<soc_version>- --model: path (including the file name) of the original network model.
- --framework: framework type of the original network model. The value 3 indicates a TensorFlow model, 5 an ONNX model, and 1 a model file in .air format of the MindSpore framework or a standard .air file exported from TorchAir through export.
- --output: path (including the file name) for storing the generated offline model after conversion, for example, $HOME/module/out/tf_resnet50, where $HOME/module/out/ is the path for storing the generated offline model, and tf_resnet50.om is the name of the generated offline model.
- --soc_version: specifies the Ascend AI Processor model. To query the value, perform the following:
- 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
- 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.
For details about more parameters and their usage, see ATC Instructions.
- If the following information is displayed, the model is converted:
1ATC run success, welcome to the next use.
After the command is executed successfully, the *.onnx model is converted to an *.om offline model adapted to the Ascend AI Processor. You can view the generated *.om offline model file in the path specified by the --output parameter.
- Perform subsequent operations.
Call acl APIs to load the obtained *.om offline model for model inference. For details about how to load a model and perform inference, see "Inference App Development Workflow".