AI Model Zoo for STM32 devices
Welcome to STM32 model zoo!
The STM32 AI model zoo is a collection of reference machine learning models that are optimized to run on STM32 microcontrollers. Available on GitHub, this is a valuable resource for anyone looking to add AI capabilities to their STM32-based projects.
These models can be useful for quick deployment if you are interested in the categories that they were trained. We also provide training scripts to do transfer learning or to train your own model from scratch on your custom dataset.
The performances on reference STM32 MCU and MPU are provided for float and quantized models.
This project is organized by application, for each application you will have a step by step guide that will indicate how to train and deploy the models.
uniform architecture
for all the use casesingle entry point
to the code : a .yaml configuration file to configure all the needed services.Bring Your Own Model (BYOM)
feature to allow the user (re-)training his own model. Example is provided here.Bring Your Own Data (BYOD)
feature to allow the user finetuning some pretrained models with his own datasets. Example is provided here.[!TIP] For all use-cases below, quick and easy examples are provided and can be executed for a fast ramp up (click on use cases links below)
For more in depth guide on installing and setting up the model zoo and its requirement on your PC, specially in the cases when you are running behind the proxy in corporate setup, follow the detailed wiki article on How to install STM32 model zoo.
Create an account on myST and then sign in to STM32Cube.AI Developer Cloud to be able access the service.
Or, install STM32Cube.AI locally by following the
instructions provided in
the user manual
in section 2, and get the path to stm32ai
executable.
stm32ai
executable.If you don't have python already installed, you can download and install it from here, a 3.9 <= Python Version <= 3.10.x is required to be able to use TensorFlow later on, we recommand using Python v3.10. (For Windows systems make sure to check the Add python.exe to PATH option during the installation process).
If using GPU make sure to install the GPU driver. For NVIDIA GPUs please refer to https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html to install CUDA and CUDNN. On Windows, it is not recommended to use WSL to get the best GPU training acceleration. If using conda, see below for installation.
Clone this repository using the following command:
git clone https://github.com/STMicroelectronics/stm32ai-modelzoo.git
cd stm32ai-modelzoo
python -m venv st_zoo
Activate your virtual environment
On Windows run:
st_zoo\Scripts\activate.bat
On Unix or MacOS, run:
source st_zoo/bin/activate
cd stm32ai-modelzoo
conda create -n st_zoo
Activate your virtual environment:
conda activate st_zoo
Install python 3.10:
conda install -c conda-forge python=3.10
If using NVIDIA GPU, install cudatoolkit and cudnn and add to conda path:
conda install -c conda-forge cudatoolkit=11.8 cudnn
Add cudatoolkit and cudnn to path permanently:
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib/' > $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
pip install -r requirements.txt
In tutorials/notebooks you will find a jupyter notebook that can be easily deployed on Colab to exercise STM32 model zoo training scripts.
[!IMPORTANT] In this project, we are using TensorFLow version 2.8.3 following unresolved issues with newest versions of TensorFlow, see more.
[!CAUTION] If there are some white spaces in the paths (for Python, STM32CubeIDE, or, STM32Cube.AI local installation) this can result in errors. So avoid having paths with white spaces in them.
[!TIP] In this project we are using the
mlflow
library to log the results of different runs. Depending on which version of Windows OS are you using or where you place the project the output log files might have a very long path which might result in an error at the time of logging the results. As by default, Windows uses a path length limitation (MAX_PATH) of 256 characters: Naming Files, Paths, and Namespaces. To avoid this potential error, create (or edit) a variable namedLongPathsEnabled
in Registry Editor under Computer/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/FileSystem/ and assign it a value of1
. This will change the maximum length allowed for the file length on Windows machines and will avoid any errors resulting due to this. For more details have a look at this link.