Pose Estimation STM32 model evaluation

The evaluation service measures the accuracy of a float or quantized pose estimation model on a labeled dataset. It accepts a Keras ( .keras, .h5), TensorFlow Lite ( .tflite), or ONNX ( .onnx, float or QDQ) model, either a pretrained model of the zoo selected by name or your own model file.

The reported metric depends on the model_type:

model_type

Metric

heatmaps_spe, spe

Mean object keypoint similarity (OKS)

yolo_mpe

mAP@0.5 and mAP@[0.5:0.95]

hand_spe, head_spe

Not supported by the evaluation service

1. Configure the YAML file

Use user_config.yaml, or update one of the example files:

1.1 Set the model and the operation mode

Set operation_mode to evaluation and model_type to the type of your model. You can evaluate a pretrained model from the zoo by name, as in evaluation_config.yaml, or your own model file with model_path. model_name and model_path cannot be used together.

operation_mode: evaluation

model:
  model_type: heatmaps_spe
  model_name: st_movenet_lightning_a100_heatmaps
  input_shape: (192, 192, 3)
  final_activation: softmax
  model_precision: w8a8_ptq      # float32 to evaluate the float version

The pretrained weights are selected with model_name, input_shape, model_precision, and the dataset of the weights, which is built from dataset_name and dataset_subsetname (see the Models guide). To evaluate your own model, replace these attributes with model_path:

model:
  model_type: heatmaps_spe
  model_path: <path-to-a-Keras-or-TFlite-or-ONNX-model-file>

If you use a quantized .tflite or .onnx model, the evaluation.target attribute selects where the inferences run: with the standard Python interpreters on the PC ( host, the default), with the C code generated by STEdgeAI on the PC ( stedgeai_host), or with the C code generated by STEdgeAI directly on the STM32N6 board ( stedgeai_n6). See evaluation_n6_config.yaml for a complete example and How to evaluate my model on STM32N6 target for the setup of the board.

evaluation:
  target: stedgeai_n6     # host, stedgeai_host, stedgeai_n6
  profile: default
  input_type: uint8       # int8 / uint8 / float32
  output_type: int8       # int8 / uint8 / float32
  input_chpos: chlast     # chlast / chfirst
  output_chpos: chlast    # chlast / chfirst

tools:
  stedgeai:
    path_to_stedgeai: C:/ST/STEdgeAI/<x.y>/Utilities/windows/stedgeai.exe

The tools section is only needed when the target is not host.

1.2 Prepare the dataset

The test set is a folder of images with their label files, as described in the Datasets guide:

dataset:
  dataset_name: custom_coco              # coco, custom_coco, or custom_dataset
  dataset_subsetname: person_17kpts      # Optional. With dataset_name, selects the pretrained weights.
  keypoints: 17                          # Number of keypoints per pose
  test_path: <test-set-folder>

The evaluation uses test_path if it is set. Otherwise, it uses the validation set: validation_path if it is set, or the validation_split (default 0.2) part of training_path. To evaluate a model trained with the training service on the same validation set, use the same validation_split and general.global_seed as in the training.

1.3 Apply preprocessing

The images must be preprocessed exactly as they were for the training of the model:

preprocessing:
  rescaling: { scale: 1/127.5, offset: -1 }
  resizing:
    aspect_ratio: fit
    interpolation: bilinear
  color_mode: rgb

The aspect_ratio attribute must be fit or padding. The labels are adapted to the resized images.

1.4 Apply post-processing ( yolo_mpe)

For yolo_mpe models, set the postprocessing section. These three attributes are required:

postprocessing:
  confidence_thresh: 0.001
  NMS_thresh: 0.1
  max_detection_boxes: 100
  • confidence_thresh: a float between 0.0 and 1.0, the score threshold to filter the detections.

  • NMS_thresh: a float between 0.0 and 1.0, the non-maximum suppression threshold to remove overlapping boxes.

  • max_detection_boxes: an integer, the maximum number of poses kept after post-processing.

These are the values of evaluation_mpe_config.yaml; the mAP depends on them. The heatmaps_spe and spe evaluations need no postprocessing section.

1.5 Hydra and MLflow settings

The mlflow and hydra sections must be present in the configuration file. Every run creates a uniquely named experiment folder, based on the date and time of the run:

hydra:
  run:
    dir: ./experiments_outputs/${now:%Y_%m_%d_%H_%M_%S}

mlflow:
  uri: ./experiments_outputs/mlruns

2. Evaluate your model

If you modified user_config.yaml, run the following command from the pose_estimation/ folder:

python stm32ai_main.py

If you updated evaluation_config.yaml, run:

python stm32ai_main.py --config-path ./config_file_examples/ --config-name evaluation_config.yaml

3. Visualize the evaluation results

The OKS ( float_model_OKS or quantized_model_OKS) or the mAP of the model is reported in the log file stm32ai_main.log under experiments_outputs/<date_time>/, and logged in MLflow. For yolo_mpe models, the precision versus recall curve at an OKS threshold of 0.5 is also displayed when general.display_figures is True (the default).

4. Chained services chain_eqe and chain_eqeb

Chained services run several steps with a single configuration file:

python stm32ai_main.py --config-path ./config_file_examples/ --config-name chain_eqe_config.yaml