MicroSpeech LSTM

Overview

MicroSpeech is a basic speech-recognition network that recognizes two command words, yes and no; every other spoken word (and silence/background noise) is classified as unknown. Given a magnitude spectrogram computed from a 1-second, 16 kHz audio clip, the network outputs a vector of class probabilities over the three classes. This variant uses a recurrent LSTM layer and is based on the TensorFlow tflite-micro MicroSpeech-with-LSTM tutorial. The model was trained on the mini_speech_commands subset of the Speech Commands dataset [1], an audio dataset of spoken words released under a Creative Commons BY 4.0 license.

This repository contains the MicroSpeech LSTM model, quantized to int8 and compiled for NXP i.MX 8M Plus, i.MX 93, i.MX 95, and i.MX 952 processors. It also contains the scripts used to regenerate these assets (recipe.sh, train_model.py, convert_model.py), an inference example (example.py) and an evaluation script (evaluate.py).

Key Features

  • Recurrent LSTM-based keyword recognizer.
  • Operates on a magnitude spectrogram extracted from a 1-second, 16 kHz audio clip.
  • Recognizes 3 classes: yes, no, and unknown.
  • ~119,923 parameters, ~0.023 MOPS.
  • int8 quantized (int8 input / int8 output) for accelerated NPU inference on NXP i.MX platforms.

Model Description

This is a quantized and compiled version of the MicroSpeech-with-LSTM model, trained from scratch by NXP on the mini_speech_commands dataset, optimized for NXP i.MX 8M Plus, i.MX 93, i.MX 95, and i.MX 952 processors.

Modifications

This model is a derivative work with the following changes from the original:

  • Training: NXP trained the model from scratch (train_model.py) on the mini_speech_commands subset of the Speech Commands dataset [1] (all words other than yes/no are grouped into unknown).
  • Quantization: Full int8 post-training quantization (int8 input / int8 output) using a representative dataset of 800 spectrograms drawn from the training split (see convert_model.py).
  • Compilation (i.MX 93): Compiled for the Ethos-U65 NPU using Vela, tags lf-6.18.20_2.0.0 and lf-6.18.37_2.1.0; both tags map 100% of the operators to the NPU.
  • Compilation (i.MX 95 / i.MX 952): Converted for the eIQ Neutron NPU using the eIQ Neutron SDK versions 3.1.3, 3.2.1, and 3.2.3.

Original model available at: TensorFlow tflite-micro MicroSpeech-with-LSTM tutorial.

Model Information

Information Value
Input shape Magnitude spectrogram (1, 49, 257), int8
Input example example_input.wav (sound file from the Speech Commands dataset [1], CC BY 4.0)
Output shape Vector of class probabilities (1, 3), int8 quantized; dequantize with the output tensor's scale / zero point. See example.py to decode it.
Output example Recognized word: no
FLOPS 0.023 MOPS
Number of parameters 119,923
File size (int8) 122 KB (assets/quantized_tflite_model/microspeech-lstm_quant_int8.tflite)
Source framework TensorFlow / Keras

Labels

The model output index order follows the training-time directory listing of the mini_speech_commands dataset:

yes, no, unknown

Supported Hardware and Software Configurations

All models run with the eIQ LiteRT (TensorFlow Lite) runtime and the corresponding NPU delegate (VX for i.MX 8M Plus, Ethos-U for i.MX 93, Neutron for i.MX 95 / i.MX 952). The same information is captured in release_manifest.json.

Asset Runtime Precision HW target BSP & SDK versions Link to asset
i.MX 8M Plus Quantized LiteRT INT8 i.MX 8M Plus - Download
i.MX 93 Precompiled LiteRT INT8 i.MX 93 BSP lf-6.18.20_2.0.0, VELA_TAG = lf-6.18.20_2.0.0 Download
i.MX 93 Precompiled LiteRT INT8 i.MX 93 BSP lf-6.18.37_2.1.0, VELA_TAG = lf-6.18.37_2.1.0 Download
i.MX 95 Precompiled LiteRT INT8 i.MX 95 BSP lf-6.18.20_2.0.0, Neutron SDK v3.1.3 Download
i.MX 95 Precompiled LiteRT INT8 i.MX 95 BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.1 Download
i.MX 95 Precompiled LiteRT INT8 i.MX 95 BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.3 Download
i.MX 952 Precompiled LiteRT INT8 i.MX 952 BSP lf-6.18.20_2.0.0, Neutron SDK v3.1.3 Download
i.MX 952 Precompiled LiteRT INT8 i.MX 952 BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.1 Download
i.MX 952 Precompiled LiteRT INT8 i.MX 952 BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.3 Download

The hardware-independent int8 model is also provided for host (x86) inference and as the input to the compilers: assets/quantized_tflite_model/microspeech-lstm_quant_int8.tflite (the i.MX 8M Plus asset above is a symlink to this same file).

Limitations and Biases

This model targets classification tasks with a very limited command vocabulary. Additional limitations:

  • Task scope: Recognizes only yes, no, and unknown; it is not a general-purpose speech-recognition model and should not be relied upon in safety-critical scenarios.
  • Fixed input format: The model expects a magnitude spectrogram computed from a 1-second, 16 kHz mono audio clip. Other sample rates, clip lengths, or noisy/far-field recordings are untested.
  • Dataset bias: The model is trained on the mini_speech_commands subset of the Speech Commands dataset. Recognition quality may vary for accents, speaking styles, microphones, or background-noise conditions that are under-represented in that dataset.

Training

The model is trained from scratch by NXP, using train_model.py, on the mini_speech_commands subset of the Speech Commands dataset [1] (all words other than yes/no are grouped into unknown). The dataset is released under a Creative Commons BY 4.0 license.

Evaluation

evaluate.py runs the int8 quantized model on the held-out test split of the mini_speech_commands dataset and reports classification accuracy. The evaluation runs on a host PC with the LiteRT CPU runtime, using the hardware-independent model (assets/quantized_tflite_model/microspeech-lstm_quant_int8.tflite), not the NPU-compiled assets.

python evaluate.py -m assets/quantized_tflite_model/microspeech-lstm_quant_int8.tflite

Download and Run

Running the example

An example of how to use the model is in example.py (run on a PC). Install the dependencies from requirements.txt first. The example loads a .wav file, computes the magnitude spectrogram, runs the LSTM model, and prints the recognized word.

# Run on PC:
python example.py -m assets/quantized_tflite_model/microspeech-lstm_quant_int8.tflite -i example_input.wav

Please refer to the i.MX Machine Learning User Guide for details on how to run the models on each platform.

Regenerating the assets with recipe.sh

The recipe installs the eIQ Neutron SDK from the NXP eIQ PyPI Distribution Portal. Configure pip once to use it:

python -m pip config --user set global.index https://eiq.nxp.com/repository
python -m pip config --user set global.index-url https://eiq.nxp.com/repository
python -m pip config --user set global.trusted-host eiq.nxp.com
python -m pip config --user set global.extra-index-url https://pypi.org/simple
python -m pip config --user set global.find-links https://eiq.nxp.com/repository/

To train, quantize the int8 model, and compile the platform-specific variants, run:

bash recipe.sh

The script takes two optional positional arguments, the Vela tag and the eIQ Neutron SDK version (defaulting to lf-6.18.20_2.0.0 and 3.2.3 respectively):

bash recipe.sh [IMX_ETHOS_U_VELA_TAG] [EIQ_NEUTRON_SDK_VERSION]
# e.g.
bash recipe.sh lf-6.18.37_2.1.0 3.2.3

The generated files are:

  • assets/quantized_tflite_model/microspeech-lstm_quant_int8.tflite - hardware-independent int8 model, also used for i.MX 8M Plus (assets/imx8mplus/microspeech-lstm_quant_int8.tflite).
  • assets/imx93/<IMX_ETHOS_U_VELA_TAG>/microspeech-lstm_quant_int8_vela.tflite - Vela-compiled for i.MX 93.
  • assets/imx95/<EIQ_NEUTRON_SDK_VERSION>/microspeech-lstm_quant_int8_converted.tflite - Neutron-converted for i.MX 95.
  • assets/imx952/<EIQ_NEUTRON_SDK_VERSION>/microspeech-lstm_quant_int8_converted.tflite - Neutron-converted for i.MX 952.

License

This model, including the quantized and compiled assets and the scripts in this repository, is released under the MIT License (see LICENSE). The original TensorFlow tflite-micro MicroSpeech-with-LSTM tutorial is also released under the MIT License. The training data (Speech Commands dataset) is released under a Creative Commons Attribution 4.0 International (CC BY 4.0) license (see MODEL_LICENSE).

Citation

If you use this model, please cite both this work and the original dataset:

@article{warden2018speech,
  title={Speech commands: A dataset for limited-vocabulary speech recognition},
  author={Warden, Pete},
  journal={arXiv preprint arXiv:1804.03209},
  year={2018}
}
Downloads last month
559
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collections including nxp/micro-speech-lstm-imx

Paper for nxp/micro-speech-lstm-imx