Image Classification with ResNet-50 (Image Decoding+Resizing+Synchronous Inference)
Description
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 to an .om offline model adapted to the Ascend AI Processor. In the sample, load the .om file, decode, resize, and infer two .jpg images, process the obtained inference results, and output the class index with the top confidence value of each image.
During model conversion, set CSC parameters to convert YUV420SP images into RGB images to meet the input requirements of the model.

Principles
The following table lists the key functions involved in this sample.
Initialization |
|
|---|---|
Device Management |
|
Stream Management |
|
Memory Management |
In media data processing, if you need to allocate device memory to store the input or output data, call acldvppMalloc to allocate memory and call acldvppFree to free up memory. |
Data Transfer |
aclrtMemcpy (used when the app runs on the host):
Data transfer is not required if your app runs in the board environment. |
Media Data Processing V1 |
|
Model Inference |
|
Data Postprocessing (Single-Operator Execution) |
Cast: casts the data type of the inference result from float32 to float16; ArgMaxD: searches for the class indexes with the top confidence values in the inference result. aclopSetModelDir: loads the single-operator model file; aclopCast: executes the Cast operator; aclopExecuteV2: executes the ArgMaxD operator. |
Directory Structure
The sample directory is organized as follows:
├── caffe_model │ ├── aipp.cfg //Configuration file with CSC parameters, used for model conversion ├── data │ ├── dog1_1024_683.jpg //Test image. Obtain the test image according to the guide and save it to the data directory. │ ├── dog2_1024_683.jpg //Test image. Obtain the test image according to the guide and save it to the data directory. ├── inc │ ├── dvpp_process.h //Header file that declares functions related to media data processing │ ├── model_process.h //Header file that declares functions related to model processing │ ├── sample_process.h //Header file that declares functions related to resource initialization and destruction │ ├── singleOp_process.h //Header file that declares the functions related to single-operator execution │ ├── utils.h //Header file that declares common functions (such as the file reading function) ├── out │ ├── op_models │ ├──├──op_list.json //Description information of operators ArgMaxD and Cast ├── src │ ├── acl.json //Configuration file for system initialization │ ├── CMakeLists.txt //Build script │ ├── dvpp_process.cpp //Implementation file of functions related to media data processing │ ├── main.cpp //Implementation file of the main function, for image classification │ ├── model_process.cpp //Implementation file of model processing functions │ ├── sample_process.cpp //Implementation file of functions related to resource initialization and destruction │ ├── singleOp_process.cpp //Implementation file of functions related to single-operator execution │ ├── utils.cpp //Implementation file of common functions (such as the file reading function) ├── .project //Project information file, including the project type, project description, and type of the target device ├── CMakeLists.txt //Build script that calls the CMakeLists file in the src directory