Ascend inference framework
Project description
[TOC]
# 1. Overview
## 1.1 Background
This project uses Python Ascend Computing Language (pyACL) APIs to implement the Ascendfly inference framework and encapsulates a series of easy-to-use Python APIs to simplify the PyACL development process and accelerate algorithm porting and deployment. The following describes the functions and dependencies of Ascendfly APIs and explains how to install and use them.
## 1.2 Functions
The project provides the following functions:
Encapsulate context and memory resource classes to simplify resource scheduling and allocation.
Encapsulate the AscendArray class, which is similar to using numpy.ndray to manage images and tensors on the device, to implement data consistency. AscendArray automatically manages data memory.
Encapsulate the VideoCapture and VideoWriter classes to obtain real-time H.264 (MAIN LEVEL without B frame) RTSP/RTMP streams and use Ascend 310 AI Processors to decode hardware or encode images into H.264/H.265 streams frame by frame.
Encapsulate the Image class to implement image processing functions such as image decoding, scaling, cropping, and padding.
Encapsulate the Model class to implement model inference.
Encapsulate the Profiling class to facilitate model performance tuning.
Provide other functions such as single-operator calling and post-processing.
## 1.3 Program Architecture
The system-level Ascendfly project includes the following modules:
Resource:
The Resource module consists of mem, context, and thread/multi-process. mem is a memory object used to allocate and deallocate memory resources. context is used to allocate and deallocate context resources. multi-process is used for parallel acceleration.
Data:
The Data module consists of AscendArray and Tensor. AscendArray implements AscendArray objects similar to numpy.ndarray. It unifies the entire framework image and tensor data and provides to_numpy, to_ascend, and clone methods that are different from ndarray to replicate numpy.ndarray data and objects. Tensor mainly implements the imgs2tensor and tensor2imgs functions to convert 3-dimensional images into 4-dimensional tensors for batch inference or tensor heatmap display.
Model: The Model module encapsulates AscendModel for model inference. After AscendModel is instantiated, model.tensor is used to obtain the input and output tensor names, feed_data is used to feed data to the model, run is used to implement inference, and get_tensor_by_name is used to obtain the output tensor data.
Image:
The Image module involves image pre-processing (dynamic AIPP), image color space conversion (colorspace), image geometric transformation (geome), and image display (misc).
Video: The Video module encapsulates the VideoCapture class for H.264/H.265 RTSP/RTMP video decoding. The implementation of the Video module is basically the same as that of OpenCV VideoCapture: pyav pulls and decompresses streams, and vdec (encapsulating the DVPP decoding function) decodes the data. The Video module also encapsulates the VideoWriter class, which encodes single-frame YUV images into H.264/H.265 real-time video streams. The implementation of the Video module is slightly different from that of the OpenCV VideoWriter class: The single-frame image data of AscendArray is encoded by using venc (encapsulating the DVPP encoding function), and the video streams are saved to the local host.
Post_process: The Post_process module uses the bbox_overlaps function to calculate the Intersection over Union (IOU) of the bounding box (bbox), uses the nms function to calculate the NonMaximumSuppression, and uses the imshow and imshow_det_bboxes commands to display the detected target bbox or write the target bbox and confidence on the image and save the image.
Ops: The Ops module calls operators in the Blas library and operators such as Argmax, Cast, Transpose, and FFT.
Profiling The Profiling module encapsulates the Profiling class to simplify operator and model performance tuning, intuitively display the execution time of each operator, and sort the operators.
The following figure demonstrates the system design.
![Description of the input image]()
## 1.4 Design Process
![Description of the input image]()
# 2 Environment Dependencies and Installation Guide
## 2.1 Environment Dependencies
Ascendfly depends on pyACL(CANN 21.0.1 or later), [pyav](https://github.com/PyAV-Org/PyAV), and [PIL](). The following describes how to install the dependent software.
Table 2-1 Environment requirements
Table 2-2 Environment-dependent software and software versions
## 2.2 Installing CANN
As Python AscendCL programming APIs, pyACL opens functions such as context creation, memory allocation, model, and operator. The Ascendfly inference framework depends on the APIs provided by pyACL. For details about the environment installation method, see [CANN Software Installation Guide](https://support.huaweicloud.com/instg-cli-cann/atlascli_03_0001.html). After installing CANN, [configure environment variables](https://support.huaweicloud.com/asdevg-python-cann/atlaspython_01_0006.html).
## 2.2 Installing Ascendfly Ascendfly automatically installs related dependencies. You can run the following command to directly install them:
`shell pip install ascendfly `
## 2.3 (Optional) Installing OpenCV
If the ARM platform is used, install Python 3.7.5 before compiling and installing OpenCV-Python.
Step 1 Download OpenCV-Python.
Step 2 Decompress OpenCV-Python.
tar -zxvf opencv-python-4.4.0.46.tar.gz && cd opencv-python-4.4.0.46
Step 3 Compile OpenCV-Python.
python3.7.5 setup.py install
# 3 Usage Guide
## 3.1 Restrictions
This section describes the Ascendfly restrictions.
Table 3-1 Restrictions
## 3.2 Preparations
Before running a model, convert the model and modify its configuration file. The storage locations of models and configuration files can be customized.
### 3.2.1 Preparing a Model
Step 1: Download a model.
Obtain the original network model, weight file, and aipp_cfg file (for details about how to download related models, visit the tools/modelzoo link), and save them to any directory of a common user in the development environment, for example, /home/model/.
Step 2: Convert the model.
Configure the AIPP by following the instructions in the [ATC Tool Instructions](https://support.huaweicloud.com/intl/en-us/tg-Inference-cann/atlasatc_16_0007.html) and convert the Caffe, TensorFlow, or ONNX model into an OM model of the Ascend platform. For details, see the tools/convert script.
### 3.2.2 Using Ascendfly APIs for Development
You can use Ascendfly APIs to develop the inference process based on the sample in the demo and [API User Guide](#4.1).
## 3.3 Demo Running
Go to the demo directory, modify the configurations such as device id and video_stream_path of the demo to be run, and run the demo.
`shell python3.7.5 yolov3_caffe_demo.py `
# 4 Appendix ## 4.1 Ascendfly APIs For details, see the index.html file in the doc directory of [Source Code](https://gitee.com/ascend-fae/ascendfly).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ascendfly-1.4.tar.gz
.
File metadata
- Download URL: ascendfly-1.4.tar.gz
- Upload date:
- Size: 75.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 129350d2be05b06263ce202eff761243e3b2acac2f234ce4e51be2109784ea5f |
|
MD5 | 75e46f08a94c05888feb1e0ac1a373f4 |
|
BLAKE2b-256 | 117f946a60eaa9bf202ebea6aae9053d18226debb53981fd2e99479a7e1416ea |
File details
Details for the file ascendfly-1.4-py3-none-any.whl
.
File metadata
- Download URL: ascendfly-1.4-py3-none-any.whl
- Upload date:
- Size: 101.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 995782aa0bd85c46b23970d28e0798e6764e1d1fb2d08a3691a3e8feb8991715 |
|
MD5 | 1af07d6c9474614887663cb0cddeb0e6 |
|
BLAKE2b-256 | 08797a42e0fbfc51b998eb46adefe5f8d35a7b3af1e612f5102a90e155d21b23 |