Model Building
For network models of open-source frameworks (such as Caffe and TensorFlow), inference cannot be directly performed on Ascend AI Processors. You need to use the Ascend Tensor Compiler (ATC) tool to convert the network models of open-source frameworks into offline model adapted to the Ascend AI Processors (*.om files).
The following uses the ResNet-50 network of the ONNX framework as an example to describe how to use the ATC tool to convert models. For details, see ATC Instructions.
- Log in to the development environment as the running user.
- Convert the model.
Run the following command to convert the original model into an .om model file 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 version of Ascend AI Processor.
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>
The parameters are described as follows. 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 Ascend AI Processor.
If you cannot determine the soc_version of the current device, perform the following steps:
- (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.
- If a message is displayed indicating that an operator is not supported during model conversion, customize the operator 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 environment variables and graph description, see in ATC Instructions.
- For details about the building and inference of models with a dynamic input shape, see Dynamic Model Inference.
- If the existing network does not meet your requirements, you can use the operators supported by Ascend AI Processor and call the Ascend Graph APIs to build your own network, and then compile the network into an .om offline model file. For details, see Ascend Graph Developer Guide.