Semantic Segmentation STM32 Model Zoo ¶
Semantic segmentation assigns a class label to every image pixel, enabling fine-grained scene understanding for applications such as road detection, medical imaging, and industrial inspection on STM32 devices.
This page takes you from dataset configuration to training, evaluation, and quantization. Each service is selected with the
operation_mode
attribute in a YAML file and launched with the same command.
Before you start ¶
Set up your Python environment as described in Getting started.
Run commands from the
semantic_segmentation/folder:cd stm32ai-modelzoo-services/semantic_segmentationPretrained model availability and compatible input sizes are listed in the TensorFlow and PyTorch model guides.
Choose your framework ¶
|
|
TensorFlow |
PyTorch |
|---|---|---|
|
Example configurations |
||
|
Full user configuration |
Use the model-specific examples in
|
|
|
Model families |
DeepLabV3 |
STDCv1, decomposed STDCv1, BiSeNetV2 |
|
|
|
|
|
|
|
|
|
Dataset names |
|
|
|
Trained model artifacts |
Keras model and exported ONNX model |
|
|
Quantized model |
TFLite or QDQ ONNX, depending on the quantizer |
QDQ ONNX (
|
For PyTorch, set
model.framework:
torch
and choose the architecture with
model.model_name. The TensorFlow service uses
model.model_type
to select the model family. See the model guides for PyTorch checkpoint details.
How a run works ¶
python stm32ai_main.py --config-path <config-folder> --config-name <config-file>.yaml
Without
--config-pathand--config-name, the TensorFlowuser_config.yamlis used. For PyTorch, start from a model-specific configuration underconfig_file_examples_pt/.Each run creates an experiment directory under
experiments_outputs/, containingstm32ai_main.log, model artifacts, and other outputs.Override YAML values on the command line, for example
training.epochs=2oroperation_mode=evaluation.Dataset paths in the examples are relative to the
semantic_segmentation/directory. Update them to match your dataset; absolute paths can also be used.
Prepare your dataset ¶
TensorFlow:
use an image directory, a matching mask directory, and split-list files. The TensorFlow loader uses
dataset_name:
coco_voc,
dataset_subsetname, and
class_names
to identify the prepared dataset and label mapping. See the TensorFlow datasets guide.
PyTorch:
configure image and mask directories for each split. Images and masks are paired by basename; split-list files are not used. Supported dataset modes are
cocostuff
(171 classes),
cocostuff_person
(person/background), and
custom
(mask IDs are preserved). See the PyTorch datasets guide for folder layouts, label mappings, and path settings.
1. Train a model ¶
TensorFlow ¶
Start with
config_file_examples/training_config.yaml. Set
model.model_type
and
model.model_name, then point the training and validation paths to your images and masks. The example uses DeepLabV3 and the COCO-VOC person subset.
python stm32ai_main.py --config-path ./config_file_examples/ --config-name training_config.yaml
PyTorch ¶
Choose the
STDC training config
or
BiSeNetV2 training config. Set the dataset paths,
dataset_name,
num_classes, and model options. For example, STDC uses
model.framework:
torch,
model.model_name:
stdcv1_pt, and a channel-first
model.input_shape.
python stm32ai_main.py --config-path ./config_file_examples_pt/stdc/ --config-name training_config.yaml
For BiSeNetV2, use
--config-path
./config_file_examples_pt/bisenet/
with the same config name. PyTorch checkpoints and the exported ONNX model are saved under the configured
general.saved_models_dir. The STDC and BiSeNetV2 training details are in the PyTorch training guide.
2. Evaluate a model ¶
Evaluation compares model predictions with annotation masks. Keep preprocessing and class mapping consistent with training, and set the validation or test image and annotation paths in the configuration.
TensorFlow ¶
Use config_file_examples/evaluation_config.yaml:
python stm32ai_main.py --config-path ./config_file_examples/ --config-name evaluation_config.yaml
PyTorch ¶
Use the STDC evaluation config or the BiSeNetV2 evaluation config:
python stm32ai_main.py --config-path ./config_file_examples_pt/stdc/ --config-name evaluation_config.yaml
See the evaluation guide for model selection, target options, and reported metrics.
3. Quantize a model ¶
Quantization uses representative calibration images. Set
dataset.quantization_path
to an image directory; annotation masks are not required for calibration.
TensorFlow ¶
Start with config_file_examples/quantization_config.yaml:
python stm32ai_main.py --config-path ./config_file_examples/ --config-name quantization_config.yaml
PyTorch ¶
Start with the STDC quantization config or the BiSeNetV2 quantization config:
python stm32ai_main.py --config-path ./config_file_examples_pt/stdc/ --config-name quantization_config.yaml
The PyTorch
onnx_quantizer
writes a QDQ ONNX model under
experiments_outputs/<date_time>/quantized_models/. See the quantization guide for supported options.
4. Run several steps at once ¶
Chained modes combine multiple services. For example,
chain_tqe
trains, quantizes, and evaluates the resulting model:
python stm32ai_main.py --config-path ./config_file_examples/ --config-name chain_tqe_config.yaml
python stm32ai_main.py --config-path ./config_file_examples_pt/stdc/ --config-name chain_tqe_config.yaml
chain_eqe
evaluates a float model, quantizes it, then evaluates the quantized model. Use the model-specific chain examples under
config_file_examples/
or
config_file_examples_pt/.
Operation modes ¶
The
operation_mode
attribute selects a service. In chained mode names,
t
= training,
e
= evaluation,
q
= quantization,
b
= benchmarking, and
d
= deployment.
|
|
Operations |
|---|---|
|
|
Train a model on a semantic-segmentation dataset. |
|
|
Evaluate a float or quantized model against a labeled dataset. |
|
|
Quantize a float model. |
|
|
Generate a segmentation map for each input image. |
|
|
Benchmark a model on an STM32 target. |
|
|
Deploy a model on an STM32 target. |
|
|
Train, quantize, and evaluate the model. |
|
|
Train, quantize, evaluate, and benchmark the model. |
|
|
Evaluate a float model, quantize it, and evaluate the quantized model. |
|
|
Evaluate a float model, quantize it, evaluate and benchmark the quantized model. |
|
|
Quantize a float model and benchmark the quantized model. |
|
|
Quantize a float model and deploy the quantized model. |
See the prediction, benchmarking, and deployment guides for those services.