Instance Segmentation STM32 model zoo ¶
Instance segmentation detects objects and predicts a pixel-level mask for each detected instance, supporting scene understanding and object counting on STM32 devices. This use case is implemented with TensorFlow tooling.
This page takes you from a quantized model to predictions on your images, a benchmark on an STM32 target, and a deployment on an STM32N6 board. Every service is selected with the
operation_mode
attribute of a YAML file and launched with the same command. Instance Segmentation uses TensorFlow only and does not provide training, evaluation, or quantization services: use quantized TFLite models.
Before you start ¶
Set up your Python environment as described in Getting started.
Run all commands from the
instance_segmentation/folder:cd stm32ai-modelzoo-services/instance_segmentationSelect a model either by name or with your own file:
By name (
model_name): pretrained models are loaded by name, and you can browse them in the ST Edge AI Model Explorer.By file (
model_path): a local path or anhttp(s)URL.model_nameandmodel_pathcannot be used together.
The available models are listed in the Models guide.
How a run works ¶
python stm32ai_main.py --config-path <config-folder> --config-name <config-file>.yaml
Without
--config-pathand--config-name, user_config.yaml is used.Each run creates
experiments_outputs/<date_time>/, which contains the logstm32ai_main.log. MLflow files are written toexperiments_outputs/mlruns.Any YAML value can be overridden on the command line, for example
operation_mode=benchmarking.The relative paths of the example configurations assume that you run from
instance_segmentation/.
1. Predict ¶
The prediction service runs a quantized TFLite model on the images of a folder and saves each image annotated with the masks and bounding boxes of the detected objects.
Edit these keys in config_file_examples/prediction_config.yaml:
model:
model_type: yolov8n_seg
model_path: <path-to-a-quantized-tflite-model> # replaces model_name, input_shape, and model_precision
dataset:
dataset_name: coco_is
classes_file_path: ./datasets/coco_classes.txt
prediction_path: <path-to-the-images-to-predict>
python stm32ai_main.py --config-path ./config_file_examples/ --config-name prediction_config.yaml
The annotated images are saved in
experiments_outputs/<date_time>/predictions/. See the
Prediction guide
for the preprocessing and postprocessing options.
2. Benchmark a model ¶
config_file_examples/benchmarking_config.yaml
benchmarks the pretrained
yolov8n
model on
STM32MP257F-EV1
with the ST Edge AI Model Bench. To choose another model or target, edit:
model:
model_path: <path-to-your-model> # replaces model_name, input_shape, pretrained_dataset_name, and model_precision
benchmarking:
board: <target-board>
python stm32ai_main.py --config-path ./config_file_examples/ --config-name benchmarking_config.yaml
See the Benchmarking guide for the tools and the results.
3. Deploy a model ¶
Deployment builds and flashes the Instance Segmentation application on an STM32N6570-DK or NUCLEO-N657X0-Q board. Edit these keys in config_file_examples/deployment_n6_yolov8n_seg_config.yaml:
tools:
stedgeai:
on_cloud: False
path_to_stedgeai: <path-to-the-stedgeai-executable>
path_to_cubeIDE: <path-to-the-stm32cubeide-executable>
deployment:
hardware_setup:
board: STM32N6570-DK # or NUCLEO-N657X0-Q
python stm32ai_main.py --config-path ./config_file_examples/ --config-name deployment_n6_yolov8n_seg_config.yaml
Set the board in dev boot mode first. The Deployment guide links to the full STM32N6 procedure.
Operation modes ¶
The
operation_mode
attribute defines the service you want to run.
|
operation_mode attribute |
Operations |
|---|---|
|
|
Predict the objects and their masks in some images using a quantized TFLite model |
|
|
Benchmark a model on an STM32 board |
|
|
Deploy a model on an STM32N6 board |
The
model_type
attribute currently supported for instance segmentation is:
yolov8n_seg: Ultralytics YOLOv8n-seg architecture. It predicts, for each object, a bounding box, a class, and mask coefficients, which are combined with mask prototypes to build the instance mask. Deployment requiresmodel_type: yolov8n_seg; it selects the YOLOv8 segmentation postprocessing of the embedded application.
Ready-to-use YAML examples are available in config_file_examples/, and user_config.yaml lists all the sections.