Pose Estimation STM32 model zoo ¶
Pose Estimation predicts the positions of body, hand, or head keypoints in an image, enabling applications such as gesture control, fitness tracking, and ergonomics monitoring on STM32 devices.
This page takes you from a dataset to a trained, quantized, and evaluated model with as few configuration changes as possible. Every service is selected with the
operation_mode
attribute of a YAML file and launched with the same command. Pose Estimation is implemented with TensorFlow only.
Before you start ¶
Set up your Python environment as described in Getting started.
Run all commands from the
pose_estimation/folder:cd stm32ai-modelzoo-services/pose_estimationPretrained models are loaded by name. You can browse them in the ST Edge AI Model Explorer.
The available models, their
model_type, and their footprints are listed in the
Models guide. Ready-to-use configurations are in
config_file_examples/, and the full user configuration is
user_config.yaml.
How a run works ¶
python stm32ai_main.py --config-path <config-folder> --config-name <config-file>.yaml
Without
--config-pathand--config-name,user_config.yamlis used.Each run creates
experiments_outputs/<date_time>/, which contains the logstm32ai_main.log, trained models in thegeneral.saved_models_dirfolder (saved_modelsby default), and quantized models inquantized_models/.Any YAML value can be overridden on the command line, for example
training.epochs=2oroperation_mode=evaluation.Use absolute paths for datasets and models.
Every pose estimation configuration needs:
model.model_type: the model family, also when you usemodel_path.A
preprocessingsection in all operation modes. Keep the values used for training.dataset.keypoints, the number of keypoints per pose, for training, evaluation, and prediction.dataset.dataset_nameset tococo,custom_coco, orcustom_datasetwhenever your dataset folders are read.mlflowandhydrasections, as in the example files.
Prepare your dataset ¶
Each split (
training_path,
validation_path,
test_path,
quantization_path,
prediction_path) is one flat folder in which every image comes with a label file of the same name, in the YOLO Darknet pose format:
dataset_root/
train/
image_1.jpg
image_1.txt
val/
image_2.jpg
image_2.txt
Each line of a label file describes one person:
class_id
x_center
y_center
width
height
x_1
y_1
v_1
...
x_K
y_K
v_K, with all coordinates normalized to [0, 1],
K
equal to
dataset.keypoints, and
v
>
0
for a labeled keypoint. Images without a label file are treated as images without pose.
If
validation_path
is empty,
validation_split
(default
0.2) of
training_path
is used for validation. For evaluation,
test_path
is used if it is set, otherwise the validation set. If no
quantization_path
is given, the training set is used for quantization.
To build such a dataset from COCO, use the
dataset converter. See the
Datasets guide
for all
dataset
options and
How to prepare my own pose estimation dataset.
1. Train a model ¶
Only
heatmaps_spe
models can be trained. Edit these keys in
config_file_examples/training_config.yaml:
model:
model_type: heatmaps_spe
model_name: st_movenet_lightning_a100_heatmaps
input_shape: (192, 192, 3)
pretrained: True # start from the pretrained weights; False trains from scratch
final_activation: softmax
dataset:
dataset_name: custom_coco
dataset_subsetname: person_17kpts # with dataset_name, selects the pretrained weights
keypoints: 17
training_path: /path/to/coco_train_single_pose
validation_split: 0.1 # used because validation_path is not set
test_path: /path/to/coco_val_single_pose
python stm32ai_main.py --config-path ./config_file_examples/ --config-name training_config.yaml
The trained model is saved as
experiments_outputs/<date_time>/saved_models/best_model.keras, and its OKS is evaluated at the end of the run on
test_path
(or on the validation set). The example trains for 2 epochs; increase
training.epochs
for a real training.
More options, such as data augmentation, learning-rate schedules, and layer freezing, are described in the Training guide.
2. Evaluate a model ¶
You can evaluate a pretrained model from the zoo by name, or your own model file with
model.model_path. The evaluation reports the mean OKS (
heatmaps_spe,
spe) or the mAP (
yolo_mpe) in
stm32ai_main.log. Keep
preprocessing
identical to the one used for training.
config_file_examples/evaluation_config.yaml
evaluates the pretrained, quantized
st_movenet_lightning_a100_heatmaps
model. Set
dataset.test_path
to your test set and run it. Use
model_precision:
float32
to evaluate the float version. For multi-pose YOLO models, start from
evaluation_mpe_config.yaml.
To evaluate your own model, replace the
model
section, because
model_name
and
model_path
cannot be used together:
model:
model_type: heatmaps_spe
model_path: /path/to/experiments_outputs/<date_time>/saved_models/best_model.keras # or .tflite / .onnx
python stm32ai_main.py --config-path ./config_file_examples/ --config-name evaluation_config.yaml
To run a quantized model on the STM32N6 board instead of the host, set
evaluation.target:
stedgeai_n6; see the
Evaluation guide.
3. Quantize a model ¶
Quantization needs calibration images that are representative of your data and preprocessed the same way as for training. In
config_file_examples/quantization_config.yaml, set
dataset.quantization_path
to your calibration folder. To quantize your own model, replace the
model
section with:
model:
model_type: heatmaps_spe
model_path: /path/to/experiments_outputs/<date_time>/saved_models/best_model.keras
python stm32ai_main.py --config-path ./config_file_examples/ --config-name quantization_config.yaml
The
TFlite_converter
quantizer saves an 8-bit
.tflite
model to
experiments_outputs/<date_time>/quantized_models/.
If no calibration data is provided (no
quantization_path
and no
training_path), the model is quantized with random data. Its accuracy is meaningless, but it can be used to estimate the footprints on target. See the
Quantization guide
for the ONNX quantizer and advanced modes.
4. Run several steps at once ¶
Chained services run consecutive steps with a single configuration file. For example,
chain_tqe
trains, quantizes, and evaluates a model:
python stm32ai_main.py --config-path ./config_file_examples/ --config-name chain_tqe_config.yaml
chain_eqe
evaluates a float model, quantizes it, and evaluates the quantized model, so you can compare their accuracy in one run. The other chains have their own example:
chain_tqeb,
chain_eqeb,
chain_qb, and
chain_qd.
Operation modes ¶
The
operation_mode
attribute defines the service you want to run. In the names of chained modes,
t
= training,
e
= evaluation,
q
= quantization,
b
= benchmarking,
d
= deployment.
|
operation_mode attribute |
Operations |
|---|---|
|
|
Train a heatmaps single pose estimation model from the model zoo (BYOD) or your own model of the same type (BYOM) |
|
|
Evaluate the accuracy of a float or quantized model on a test or validation dataset |
|
|
Quantize a float model |
|
|
Predict and draw the keypoints of the poses in images using a float or quantized model |
|
|
Benchmark a float or quantized model on an STM32 board |
|
|
Deploy a model on an STM32 board |
|
|
Sequentially: training, quantization of trained model, evaluation of quantized model, benchmarking of quantized model |
|
|
Sequentially: training, quantization of trained model, evaluation of quantized model |
|
|
Sequentially: evaluation of a float model, quantization, evaluation of the quantized model |
|
|
Sequentially: quantization of a float model, benchmarking of quantized model |
|
|
Sequentially: evaluation of a float model, quantization, evaluation of quantized model, benchmarking of quantized model |
|
|
Sequentially: quantization of a float model, deployment of quantized model |
See the Benchmarking, Prediction, and Deployment guides for the other services.
Supported model types ¶
The
model_type
attribute selects the output format and the post-processing of the model:
|
|
Models |
Training |
Evaluation |
Prediction |
Deployment |
|---|---|---|---|---|---|
|
|
Single pose estimation models that output one heatmap per keypoint, post-processed to get the keypoint positions and confidences |
✅ |
✅ |
✅ |
STM32N6 |
|
|
Single pose estimation models that output the keypoint positions and confidences directly |
❌ |
✅ |
✅ |
❌ |
|
|
Ultralytics YOLO multiple pose estimation models: the output of an object detection model with a set of keypoints for each box |
❌ |
✅ |
✅ |
STM32N6, STM32MPU |
|
|
Single hand landmarks models that output the keypoint positions and confidences of the hand |
❌ |
❌ |
✅ |
❌ |
|
|
Single head landmarks models that output the keypoint positions of the head |
❌ |
❌ |
✅ |
❌ |
Quantization and benchmarking accept any model type.