Build and run a letter recognition NN model on an STM32L4 Discovery board
Introduction
Prepare development environment
Collect training data
Train the model
Feature extraction
Run the model on development board
Next Steps
Build and run a letter recognition NN model on an STM32L4 Discovery board
In this Learning Path, you will build a neural network model with TensorFlow and deploy the model on the STM32 B-L475E-IOT01A2 board . This board has an MCU based on the Arm Cortex-M4 processor.
You will implement a letter recognition model which takes accelerometer data from the board and predicts the letter based on the accelerometer data.
Set up Anaconda
Anaconda is a distribution of Python language for data science and machine learning. With Anaconda, you can easily install open-source machine learning packages.
- Visit the official Anaconda page.
- Download the Anaconda Installer, and install using default options.
With Anaconda installed, you will now install the necessary conda packages for data collection and machine learning including
Jupyter notebook
.
Follow the steps as shown below:
- Open
Anaconda Prompt - Create an environment with:
conda create -n ml_lab python=3.8
- Activate your environment with:
conda activate ml_lab
- Add
conda-forgechannel to install packages:
conda config --add channels conda-forge
- Then install necessary python packages:
conda install jupyter pandas pyserial scikit-learn tensorflow matplotlib
Set up development board
Next, you need to program the STM32 B-L475E-IOT01A2 board to acquire accelerometer data for your neural network model.
The data collection code for this Learning Path is provided, so you can import the project and program the board using STM32CubeIDE .
Download the
zip file
and extract it into a tf_stm32 folder.
Install STM32CubeIDE
Download and run the installer from the Get Software section of the
STMicroelectronics website
.
Program the board
Within STM32CubeIDE follow the steps below:
- Select
Import projectand navigate toGeneral>Existing Projects into Workspace. - Select the
MCU Dataset Creationfolder from the unzipped package as the root directory, and selectDataset_Creationproject. ClickFinishto import. - Connect board to host computer via USB. You may need to reset your board before you program the board. Click the black button on the board for the reset.
- Right click the project and select
Run As. The project will rebuild, and be flashed to the device. If prompted, accept any suggested firmware updates.
Open Jupyter Notebook
In the same environment you activated using Anaconda earlier, navigate to your tf_stm32 folder and enter:
jupyter notebook tf_stm32.ipynb
You are now ready to train your first neural network model with TensorFlow and deploy the inference with STM Cube AI.