pyACL API Call Sequence
By calling pyACL APIs, you can develop applications that provide functions such as model inference, media data processing, and single-operator execution. These functions can exist independently or in combinations. The following figure shows the overall sequence of calling pyACL APIs to develop AI applications.
In the preceding figure,the main API call sequence is abstracted based on the typical functions involved in app development. The specific scenarios are as follows:
- If the size of the input image does not meet the model requirements, media data processing is required.
- To implement model inference, the model needs to be loaded first. On the completion of model inference, the model needs to be unloaded.
- After model inference, the inference result needs to be postprocessed for looking up the class indexes with the top confidence values.
The API call process is as follows:
- Initializes pyACL.
- Allocate runtime resources.
For details, see Runtime Resource Allocation.
- Model inference, media data processing, and single-operator execution
- Model inference
- Load a model. Before inference, load the model to the system. Use offline model adapted to the Ascend AI Processor. If you need to build a model, see Model Building.
For the API call sequence, see Loading a Model.
- (Optional) Process media data, including JPEG image and video decoding, image cropping, resizing, format conversion, and JPEG image encoding.
For the API call sequence, see DVPP Image/Video Processing (Media Data Processing).
- Run model inference to implement functions such as image classification and target recognition.
For the API call sequence, see Executing a Model.
- (Optional) Data postprocessing: Postprocess the model inference result as required. For example, you can export the inference result to a file, and look up in the inference result for the class with the highest confidence score using single-operators.
- Call acl.mdl.unload to unload a model.
- Load a model. Before inference, load the model to the system. Use offline model adapted to the Ascend AI Processor. If you need to build a model, see Model Building.
- Operator execution
If your AI app involves not only model inference but also mathematical operations, such as Basic Linear Algebra Subprogram (BLAS) and data type conversion, Ascend CANN supports single-operator calling, a lightweight mode allowing you to load and execute single-operators directly using the pyACL APIs, which requires no model building and training. In addition, you can verify the functions of a custom operator via single-operator calling. For the API call sequence, see API Call Sequence.
- Model inference
- Destroy runtime allocations.
For details, see Runtime Resource Deallocation.
- Deinitialize pyACL.
Memory allocation and deallocation, data transfer (by memory copy), and data type creation and destruction are the most frequently-used calls in each phase of the app development, and therefore are not thoroughly illustrated in the flowchart. For details, see Memory Management. For details about data types, see Data Types and Operation APIs.