Audio Event Detection model quantization

Audio Event Detection (AED) quantization supports Keras and ONNX models. The available quantizers are TFlite_converter for Keras models and Onnx_quantizer for Keras and ONNX models.

For the shared quantization workflow follow the STM32 model quantization guide. For advanced ONNX modes—including tensor inspection, mixed-precision quantization, calibration dataset search, and Qmn/AdaQuant—see the advanced ONNX quantization guide.

Audio Event Detection YAML examples are available in the public repository:

To compare the accuracy of a model before and after quantization, see the quantization accuracy comparison tutorial.

The sections below describe what is specific to AED. You still need a dataset, model, feature_extraction and preprocessing section. We strongly recommend you follow the training guide first.

1. AED-specific configuration

1.1 Using an available configuration file

The pretrained models in the ST Edge AI Model Explorer directory contains several subfolders, one for each model architecture. Some of these models need quite different preprocessing, feature extraction and training parameters, and using different ones could lead to wildly varying performance.

Each of these subdirectories contains the config.yaml file that was used to train the model. To use these in quantization, copy them over to the audio_event_detection folder, rename them to user_config.yaml, and set operation_mode to quantization.

If you want to reproduce the listed performance, we recommend you use these available YAML files. Performance may be quite different if you use different parameters.

1.2 Calibration dataset

Quantization uses a representative dataset to calibrate the quantized model. Using representative data may improve quantization results, so it is recommended to provide one. For AED, the calibration data is provided with the quantization_audio_path and quantization_csv_path attributes of the dataset section, in the ESC format:

dataset:
   dataset_name: esc10
   class_names: ['dog', 'chainsaw', 'crackling_fire', 'helicopter', 'rain', 'crying_baby', 'clock_tick', 'sneezing', 'rooster', 'sea_waves']
   file_extension: '.wav'
   quantization_csv_path: <dataset-csv-file>         # Dataset to use as representative data
   quantization_audio_path: <dataset_audio_folder>   # Dataset to use as representative data
   quantization_split: 0.1                           # Optional, use 10% of the quantization set

The calibration data is selected as follows:

  • If quantization_csv_path and quantization_audio_path are set, the quantization set is used.

  • Otherwise, if a training set is available (training_csv_path and training_audio_path), the training set is used. This is useful when running a chain mode such as chain_tqe or chain_tqeb, where a training set is already required.

  • Otherwise, quantization is performed using fake (random) data. There is no interest in evaluating the resulting model, but this can be useful to quickly estimate the model footprints on a target after quantization.

The quantization_split attribute sets the fraction of the selected set to use for calibration. By default, its value is 1.0, meaning that the whole set is used. Training sets are large and quantization run times could be very long, so it is recommended to set quantization_split to use only a portion of the dataset. For example, quantization_split: 0.05 uses 5% of the set.

For quantization, the validation and test datasets do not matter. For a description of every parameter of the dataset section, see the datasets guide.

1.3 Preprocessing and feature extraction

The preprocessing and feature_extraction sections are required, and must use the same parameters as the ones used to train the model. See Audio temporal domain preprocessing and Audio feature extraction in the training guide for a description of these sections.

1.4 Quantization parameters

quantization section details are explained in STM32 model quantization guide and in advanced ONNX quantization guide for more advanced parameters. To deploy an AED model with the STM32 application code, quantize it with an int8 input and a float output: set quantization_input_type to int8 and quantization_output_type to float. See the deployment guide. When using Onnx_quantizer, the quantization_config.yaml example uses the onnx_quant_parameters.op_types_to_quantize attribute to quantize all operators except the final softmax, in order to preserve a float output.