Sample Overview
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, decode, resize and infer two .jpg images, obtain the inference results, process the inference results, and outputs the class indexes with the top confidence values.
During model conversion, set CSC parameters to convert YUV420SP images into RGB images to meet the input requirements of the model.
Main APIs
The following table lists the main APIs.
Initialization |
|
|---|---|
Device management |
|
Stream management |
|
Memory management |
If device memory is needed to store the input or output data before media data processing, call acl.media.dvpp_malloc to allocate memory and acl.media.dvpp_free to deallocate memory. |
Data transfer |
If your app runs on the host, call the acl.rt.memcpy API.
Data transfer is not required if your app runs in the board environment. |
Media data processing V1 |
|
Model inference |
|
Data postprocessing (single-operator calling) |
Process the model inference result. Call Cast to convert the data type of the inference result from float32 to float16, and then call ArgMaxD to search for the class indexes with the maximum confidence values in the inference result. Load the single-operator model file by calling acl.op.set_model_dir, execute the Cast operator by calling acl.op.cast, and execute the ArgMaxD operator by calling acl.op.execute_v2. |
Directory Structure
The directory structure is as follows:
vpc_resnet50_imagenet_classification ├──scripts │ ├── host_version.conf // Version number configuration file. │ └── testcase_300.sh // Run script. ├──src │ ├── acl_dvpp.py // Image resizing implementation file │ ├── acl_model.py // Model inference implementation file │ ├── acl_op.py // Single-operator precision conversion implementation file │ ├── acl_sample.py // Running file │ ├── acl_util.py // Implementation file of tool functions │ └── constant.py // Constant definition ├── data // Test data, which needs to be deployed by users. │ ├── fusion_result.json // File generated after atc conversion, which records the fused operator information. │ ├── dog1_1024_683.jpg │ └── dog2_1024_683.jpg ├── caffe_model // Model deployed by users. │ ├── aipp.cfg // Model configuration data. │ ├── resnet50.caffemodel // ResNet-50 model │ └── resnet50.prototxt // ResNet-50 network file ├── op_models // Directory generated after ATC conversion. │ ├── 0_Cast_0_2_1000_1_2_1000.om // Precision conversion custom operator │ ├── 1_ArgMaxD_1_2_1000_3_2_1.om // Precision conversion custom operator │ └── op_list.json // Configuration file of the precision conversion operator └── model // Directory generated after the inference model is converted. │ └── resnet50_aipp.om └── README_CN.md