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

  1. Set up your Python environment as described in Getting started.

  2. Run commands from the semantic_segmentation/ folder:

    cd stm32ai-modelzoo-services/semantic_segmentation
    
  3. Pretrained model availability and compatible input sizes are listed in the TensorFlow and PyTorch model guides.

Choose your framework

TensorFlow

PyTorch

Example configurations

config_file_examples/

STDC and BiSeNetV2

Full user configuration

user_config.yaml

Use the model-specific examples in config_file_examples_pt/

Model families

DeepLabV3

STDCv1, decomposed STDCv1, BiSeNetV2

model_name examples

st_deeplabv3_mnv2_a050_s16_asppv2

stdcv1_pt, st_stdcv1_decomposed_pt, bisenetv2_pt

model.input_shape

(height, width, channels), e.g. (416, 416, 3)

[channels, height, width], e.g. [3, 320, 320]

Dataset names

coco_voc with a configured subset

cocostuff, cocostuff_person, custom

Trained model artifacts

Keras model and exported ONNX model

.pth checkpoints and exported ONNX model

Quantized model

TFLite or QDQ ONNX, depending on the quantizer

QDQ ONNX ( onnx_quantizer)

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-path and --config-name, the TensorFlow user_config.yaml is used. For PyTorch, start from a model-specific configuration under config_file_examples_pt/.

  • Each run creates an experiment directory under experiments_outputs/, containing stm32ai_main.log, model artifacts, and other outputs.

  • Override YAML values on the command line, for example training.epochs=2 or operation_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.

operation_mode

Operations

training

Train a model on a semantic-segmentation dataset.

evaluation

Evaluate a float or quantized model against a labeled dataset.

quantization

Quantize a float model.

prediction

Generate a segmentation map for each input image.

benchmarking

Benchmark a model on an STM32 target.

deployment

Deploy a model on an STM32 target.

chain_tqe

Train, quantize, and evaluate the model.

chain_tqeb

Train, quantize, evaluate, and benchmark the model.

chain_eqe

Evaluate a float model, quantize it, and evaluate the quantized model.

chain_eqeb

Evaluate a float model, quantize it, evaluate and benchmark the quantized model.

chain_qb

Quantize a float model and benchmark the quantized model.

chain_qd

Quantize a float model and deploy the quantized model.

See the prediction, benchmarking, and deployment guides for those services.