Sample Overview

Function Usage

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

According to the arguments of the app, the following functions can be implemented:

  • Decode a .jpg image into an input image in YUV420SP (NV12) format, resize the image, and perform model inference. Then process the inference result and output the top 5 confidence values.
  • Crop an input image in YUV420SP (NV12) format and perform model inference. Then process the inference result and output the top 5 confidence values.
  • Crop and paste an input image in YUV420SP (NV12) format and perform model inference. Then process the inference result and output the top 5 confidence values.
  • Encode an input image in YUV420SP (NV12) format into a .jpg image.
  • Resize the 8192 x 8192 input image in YUV420SP (NV12) format to obtain a 4000 x 4000 subimage.
  • Crop the input images in YUV420SP (NV12) format in batches.
  • Crop and paste the input images in YUV420SP (NV12) format in batches.

Main APIs

The following table lists the main APIs.

Initialization

  • Call acl.init to initialize the configuration.
  • Call aclFinalize for deinitialization.

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.
  • Call acl.rt.synchronize_stream to block the programs until all tasks in the specified stream are complete.

Memory management

  • Call acl.rt.malloc_host to allocate host memory.
  • Call acl.rt.free_host to deallocate the memory on the host.
  • Call acl.rt.malloc to allocate device memory.
  • Call acl.rt.free to deallocate device memory.

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.

  • 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.

Media data processing V1

  • Image encoding

    Call acl.media.dvpp_jpeg_encode_async to encode a YUV420SP image into a *.jpg image.

  • Image decoding

    Call acl.media.dvpp_jpeg_decode_async to decode *.jpg images into YUV420SP images.

  • Resizing

    Call acl.media.dvpp_vpc_resize_async to resize the YUV420SP input.

  • Cropping

    Call acl.media.dvpp_vpc_crop_resize_async to crop the specified area of the input image, and then overwrite the cropped area to the output buffer as the output image.

  • Cropping and pasting

    Call acl.media.dvpp_vpc_crop_resize_paste_async to crop the specific area of the input image, and then overwrite the cropped area to the specified area of the target image as the output image.

Model inference

  • Call acl.mdl.load_from_file_with_mem to load a model from an .om file.
  • Call acl.mdl.execute to perform model inference.

    Before inference, use the CSC parameters in the .om file to convert a YUV420SP image into an RGB image.

  • Call acl.mdl.unload to unload a model.

Directory Structure

The directory structure is as follows:

vpc_jpeg_resnet50_imagenet_classification
├──scripts
│ ├── host_version.conf // Version number configuration file.
│ └── testcase_300.sh // Run script.
├──src
│ ├── acl_dvpp_process.py // Media data processing.
│ ├── acl_model_process.py // Model running file.
│ ├── constant.py // Constant definition.
│ └── main.py // Running file for process logic control.
├── data
│ ├── fusion_result.json // File generated after atc conversion, which records the fused operator information.
│ └── vdec_h265_1frame_rabbit_1280x720.h265 // Video file to be processed by the user, which is obtained by the user.
├── caffe_model // Model deployed by users.
│ ├── aipp.cfg // Model configuration data.
│ ├── resnet50.caffemodel // ResNet-50 model
│ └── resnet50.prototxt // ResNet-50 network file
└── model // Directory generated after the inference model is converted.
  └── resnet50_aipp.om // Model file generated after conversion.