1. Article purpose[edit source]
This article describes how to run an inference on the STM32MPx using the STAI MPU Python API. It is an example based on an image classification application. The unified architecture of the API allows deploying the same application on all the STM32MPx platforms using several model formats.
Information |
This article provides a simple inferencing example using the STAI MPU Python API. If you wish to explore more of the functions provided by the API, please refer to the STAI MPU Python Reference. |
2. STAI MPU Python API[edit source]
STAI MPU is a cross STM32MPx platforms machine learning and computer vision inferencing API with a flexible interface to run several deep learning models formats such as TFLite, ONNX and NBG. If you wish to learn more about the API structure please refer to STAI MPU: AI unified API for STM32MPUs. In the next section we explore, with a basic image-classification example, how to inference your models on the board using the STAI MPU Python API whether you are running a TFLite, an ONNX or an NBG model on either STM32MP1x or STM32MP2x.
3. Running an inference using the STAI MPU C++ API[edit source]
3.1. Install runtime prerequisites on the target[edit source]
After having configured the AI OpenSTLinux package, you can install the X-LINUX-AI components and the packages needed to run the example. First, we start by installing main packages needed for image processing which are Python Numpy, Python OpenCV.
Board $> apt-get install python3-numpy python3-opencv
Then, we will need to install the API plugins required during runtime depending on the model format used for the inference:
- If you are using a TFLite™ model, please run the following command:
x-linux-ai -i stai-mpu-tflite
- If you are using an ONNX™ model, please run the following command:
x-linux-ai -i stai-mpu-ort
- If you are running your model on an STM32MP2 board and running and NBG model, please run the following command:
x-linux-ai -i stai-mpu-ovx
Information |
It is important to mention that the package stai-mpu-ovx is not available on STM32MP1x boards and the TFLite™ and ONNX™ runtimes supported by the API are running exclusively on CPU. |