Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Introduction

The STM32N6 is a powerful microcontroller launched by STMicroelectronics, primarily targeting edge AI applications. You can think of it as a “super brain” for smart devices. Unlike traditional MCUs that rely on a single core, it employs a “combination punch,” making it particularly suitable for scenarios requiring real-time image recognition, speech processing, and other AI tasks.

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

I am fortunate to use the STM32N6570-DK development board for development and testing.

The development difficulty of the N6 is quite high, and I have spent the past year exploring its usage in my spare time.

In this issue, we will detail how to validate a known model using the STM32N6570-DK.

1

Preparation Tools

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

We need to prepare an STM32N6-DK (Nucleo is also acceptable, but I am using the DK version).

Install STM32CubeProgram

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Install STM32CubeIDE (IAR environment is also acceptable)

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Install STEdgeAI Core

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Since we need to use a Python environment, I installed PyCharm

Quick Evaluation of Deep Learning Models on the STM32N6 MCUQuick Evaluation of Deep Learning Models on the STM32N6 MCU

Here, I chose to test a model from the STM32 AI model library.

2

Environment Configuration

The environment configuration step is quite troublesome and can encounter many issues.

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

First, in STEdgeAI, we can find stedgeai.exe, which can help us convert the model into a .c file via the command line.

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Enter the directory of stedgeai.exe in PowerShell and run the command provided in the manual:

stedgeai generate -m mobilenet_v2_0.35_224_fft_int8.tflite --target stm32n6 --st-neural-art

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Since the model directory is not set in the environment variables, it cannot be found directly. Here, we will use direct addressing:

stedgeai generate -m F:\Code\STAI\AIProject\mobilenet_v2_0.35_224_fft_int8.tflite --target stm32n6 --st-neural-art

Directly use absolute address to add the model location.

Quick Evaluation of Deep Learning Models on the STM32N6 MCUQuick Evaluation of Deep Learning Models on the STM32N6 MCU

We can see that the corresponding file was generated successfully.

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Next, configure the relevant settings for running on the N6:

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Open the N6_scripts project directory in PyCharm, which can be found where STEdgeCore is installed.

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Configure the Python base interpreter, do not use the built-in base interpreter; use the base interpreter from STEdgeCore.

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Modify the configuration file corresponding to the project:

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Change the compiler type and tool path; even a small error here can cause the script to fail.

After modifying the configuration, apply it in the terminal.

python n6_loader.py --n6-loader-config ./config.json

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

If it shows Successfully, the configuration is complete.

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

Similarly, we need to modify the config_n6l.json configuration, mainly to change the location of the generated model file (.c):

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

We also need to apply the configuration file:

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

3

Speed Test

After completing the above environment configuration, we can burn the test program and pull up the BooT1 of the development board to enter the Bootloader.

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

python n6_loader.py

Run n6_loader.py code

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

$env:PYTHONPATH = "D:\ST\STEdgeAI\2.2\scripts\ai_runner"

Make sure to add this directory to the environment variable!!!!

python D:\ST\STEdgeAI\2.2\scripts/ai_runner/examples/checker.py -d serial:921600 --perf-only -b 10

Next, run Check.py to perform model inference on ten random samples (an error will occur if the environment variable is not added)

Quick Evaluation of Deep Learning Models on the STM32N6 MCUQuick Evaluation of Deep Learning Models on the STM32N6 MCU

Obtain evaluation data on the model’s running speed.

Quick Evaluation of Deep Learning Models on the STM32N6 MCUQuick Evaluation of Deep Learning Models on the STM32N6 MCUQuick Evaluation of Deep Learning Models on the STM32N6 MCU

stedgeai validate -m F:\Code\STAI\AIProject\mobilenet_v2_0.35_224_fft_int8.tflite --target stm32n6 --mode target -d serial:921600

Similarly, we can quickly evaluate the accuracy of the model:

Quick Evaluation of Deep Learning Models on the STM32N6 MCUQuick Evaluation of Deep Learning Models on the STM32N6 MCU

We obtain the model evaluation report (though I can’t understand it), and there is also a routine for inputting samples for real accuracy analysis.

The AI summary is as follows:

Quick Evaluation of Deep Learning Models on the STM32N6 MCU

4

Future Functions to Explore

Next, I will mainly look into how to deploy the model on the actual machine.

Leave a Comment