Instance Segmentation STM32N6 Model Deployment
January 22, 2026 ยท View on GitHub
This tutorial demonstrates how to deploy a pre-trained instance segmentation model built with quantized tflite or ONNX QDQ on an STM32N6 board using STEdgeAI.
Table of contents
1. Before you start
1.1 Hardware Setup
The application code runs with either:
-
STM32N6570-DK discovery board
-
NUCLEO-N657X0-Q nucleo board
-
And one of the following camera modules:
- MB1854 IMX335 camera module (provided with STM32N6570-DK board)
- STEVAL-55G1MBI
- STEVAL-66GYMAI1 Note: Camera detected automatically by the firmware, no config required.
-
Optional screen for nucleo board:
1.2 Software requirements
- STEdgeAI to generate network C code from tflite/onnx model.
- STM32CubeIDE to build the embedded project.
2. Configuration file
To deploy your model, you need to fill a YAML configuration file with your tools and model info, and then launch stm32ai_main.py.
As an example, we will show how to deploy yolov8n_256_quant_pc_ii_seg_coco-st.tflite pre-trained on the COCO person dataset using the necessary parameters provided in yolov8n_seg_256_config.yaml. To get this model, download it from the ST Ultralytics fork and put it in the corresponding ModelZoo folder (instance_segmentation/yolov8n_seg/).
To configure the deployment, edit ../config_file_examples/deployment_n6_yolov8n_seg_config.yaml.
2.1 Setting the model and the operation Mode
model:
model_type: yolov8n_seg # yolov8n_seg
# path to a `.tflite` or `.onnx` file.
model_path: ../../stm32ai-modelzoo/instance_segmentation/yolov8n_seg/yolov8n_256_quant_pc_ii_seg_coco-st.tflite
Configure the operation_mode section as follow:
operation_mode: deployment
2.2 Dataset configuration
2.2.1 Dataset info
Configure the dataset section in the YAML file as follows:
dataset:
dataset_name: coco_is
classes_file_path : ./datasets/coco_classes.txt
2.2.2 Preprocessing info
preprocessing:
resizing:
interpolation: bilinear
aspect_ratio: crop
color_mode: rgb # rgb, bgr
```s
- `aspect_ratio`:
- `crop`: Crop both pipes to nn input aspect ratio; Original aspect ratio kept
- `fit`: Resize both pipe to NN input aspect ratio; Original aspect ratio not kept
- `full_screen` : Resize camera image to NN input size and display a maximized image. See [Aspect Ratio Mode](../../application_code/instance_segmentation/STM32N6/Doc/Build-Options.md#aspect-ratio-mode)
- `color_mode`:
- `rgb`
- `bgr`
#### 2.2.3 Post processing info
The --use case--- models usually have a post processing to be applied to filter the model output and show final results on an image.
Post processing parameters can be configured.
```yaml
postprocessing:
confidence_thresh: 0.5
NMS_thresh: 0.5
yolo_anchors: # Only applicable for YoloV2
max_detection_boxes: 10
confidence_threshA float between 0.0 and 1.0, the score thresh to filter detections.NMS_threshA float between 0.0 and 1.0, NMS thresh to filter and reduce overlapped boxes.yolo_anchors: List of anchors. Only used with Yolov2max_detection_boxesAn int to filter the number of bounding boxes. Warning: The higher the number, the more memory is used. Our models are validated with 10 boxes.
2.3 Deployment parameters
To deploy the model in STM32N6570-DK board, you will use:
- STEdgeAI to convert the model into optimized C code
- STM32CubeIDE to build the C application and flash the board.
These steps will be done automatically by configuring the tools and deployment sections in the YAML file as the following:
tools:
stedgeai:
optimization: balanced
on_cloud: True
path_to_stedgeai: C:/ST/STEdgeAI/<x.y>/Utilities/windows/stedgeai.exe
path_to_cubeIDE: C:/ST/STM32CubeIDE_<*.*.*>/STM32CubeIDE/stm32cubeide.exe
deployment:
c_project_path: ../application_code/instance_segmentation/STM32N6/
IDE: GCC
verbosity: 1
hardware_setup:
serie: STM32N6
board: STM32N6570-DK # NUCLEO-N657X0-Q or STM32N6570-DK
output: "UVCL" # default image output interface; "UVCL" (USB display) or "SPI" (X-NUCLEO-GFX01M2). Used only with NUCLEO-N657X0-Q
tools/stedgeaioptimizationString, define the optimization used to generate the C model, options: "balanced", "time", "ram".on_cloudBoolean, True/False.path_to_stedgeaiPath to stedgeai executable file to use local download, else False.
tools/path_to_cubeIDEPath to stm32cubeide executable file.deploymentc_project_pathPath to application C code project.IDEGCC, only supported option for stm32ai application code.verbosity0 or 1. Mode 0 is silent, and mode 1 displays messages when building and flashing C application on STM32 target.serieSTM32N6boardSTM32N6570-DK or NUCLEO-N657X0-Q, see the README for more details.output"SPI" to use X-NUCLEO-GFX01M2. "UVCL" to use USB/UVC host as display. Only used for NUCLEO-N657X0-Q.
2.4 Hydra and MLflow settings
The mlflow and hydra sections must always be present in the YAML configuration file. The hydra section can be used to specify the name of the directory where experiment directories are saved. This pattern allows creating a new experiment directory for each run.
hydra:
run:
dir: ./src/experiments_outputs/${now:%Y_%m_%d_%H_%M_%S}
The mlflow section is used to specify the location and name of the directory where MLflow files are saved, as shown below:
mlflow:
uri: ./src/experiments_outputs/mlruns
3. Deployment
3.0 Boot modes
The STM32N6 does not have any internal flash. To retain your firmware after a reboot, you must program it in the external flash. Alternatively, you can load your firmware directly from SRAM (dev mode). However, in dev mode if you turn off the board, your program will be lost.
Boot modes:
- Dev mode (STM32N6570-DK: both boot switches to the right, NUCLEO-N657X0-Q: BOOT0 JP1 in position 1, BOOT1 JP2 in position 2): used to load the firmware from debug session in RAM, or program firmware in external flash
- Boot from flash (STM32N6570-DK: both boot switches to the left, NUCLEO-N657X0-Q: BOOT0 JP1 in position 1, BOOT1 JP2 in position 1): used to boot the firmware in external flash
3.1 STM32N6570-DK
1. Connect the CSI camera module to the STM32N6570-DK discovery board with a flat cable.
2. Connect the discovery board from the STLINK-V3EC USB-C port to your computer using an USB-C to USB-C cable.
Warning: using USB-A to USB-C cable may not work because of possible lack of power delivery.
3. Set to dev mode and disconnect/reconnect the power cable of your board.
4. Once deployment_n6_yolov8n_seg_config.yaml filled, launch:
python stm32ai_main.py --config-path ./config_file_examples/ --config-name deployment_n6_yolov8n_seg_config.yaml
5. Once the application deployment complete, set to boot from flash mode and disconnect/reconnect the power cable of your board.
6. When the application is running on the STM32N6570-DK board, the LCD displays the following information:
- Data stream from camera board
- The inference time
- Bounding boxes
- The number of detected object
- The segmentation mask
3.2 NUCLEO-N657X0-Q
1. Connect the CSI camera module to the NUCLEO-N657X0-Q nucleo board with a flat cable.
2. Connect the nucleo board from the STLINK-V3EC USB-C port to your computer using an USB-C to USB-C cable.
Warning: using USB-A to USB-C cable may not work because of possible lack of power delivery.

3. Set to dev mode and disconnect/reconnect the power cable of your board.
4. Once deployment_n6_yolov8n_seg_config.yaml filled, launch:
python stm32ai_main.py --config-path ./config_file_examples/ --config-name deployment_n6_yolov8n_seg_config.yaml
5. Once the application deployment complete, set to boot from flash mode and disconnect/reconnect the power cable of your board.
6. When the application is running on the NUCLEO-N657X0-Q board, the LCD displays the following information:
- Data stream from camera board
- The inference time
- Bounding boxes
- The number of detected object
- The segmentation mask