Sample Overview

Sample Obtaining

Click synchronous inference to obtain the sample.

Function Usage

This sample shows how to classify images based on the Caffe ResNet-50 network (single input with batch size = 1).

Convert the model file of the Caffe ResNet-50 network into an offline model (.om file) adapted to the Ascend AI Processor. In the sample, load the .om file, infer two .jpg images synchronously, obtain the inference results, process the inference results, and outputs the class indexes with the top 5 confidence values.

Main APIs

The following table lists the main APIs.

A device indicates the neural-network processing unit (NPU) on the board environment. For the SoC, there is only one device.

Initialization

  • Call acl.init to initialize the configuration.
  • Call acl.finalize to deinitialize the configuration.

Device management

  • Call acl.rt.set_device to specify the compute device.
  • Call acl.rt.get_run_mode to obtain the running mode of the software stack. The internal processing process varies according to the running mode.
  • Call acl.rt.reset_device to reset the current device and reclaim the associated resources.

Stream management

  • Call acl.rt.create_stream to create a stream.
  • Call acl.rt.destroy_stream to destroy a stream.

Memory management

  • Call acl.rt.malloc to allocate device memory.
  • Call acl.rt.free to deallocate device memory.

Data transfer

If your app runs on the host, call the acl.rt.memcpy API.

  • Transfers decode source data from the host to the device.
  • Transfers the inference result from the device to the host.

Data transfer is not required if your app runs in the board environment.

Model inference

  • Call acl.mdl.load_from_file_with_mem to load a model from an .om file.
  • Call acl.mdl.execute to run model inference. This API is synchronous.
  • Call acl.mdl.unload to unload a model.

Data postprocessing

Provides sample code to process the model inference result and display the class indexes with top 5 confidences on the device.

Directory Structure

The directory structure is as follows:

resnet50_imagenet_classification
├──scripts
│ ├── host_version.conf // Version number configuration file.
│ └── testcase_300.sh // Run script.
├──src
│ ├── acl_net.py // Running file
│ └── constant.py // Constant definition
├── data // Test data, which needs to be deployed by users.
│ ├── dog1_1024_683.jpg // Test image data
│ └── dog2_1024_683.jpg // Test image data
├── README_CN.md 
├── caffe_model // Model deployed by users.
│ ├── resnet50.caffemodel // ResNet-50 model
│ └── resnet50.prototxt // ResNet-50 network file
└── model // Directory generated after the inference model is converted.
  └── resnet50.om // Model file generated after conversion