Skip to content

This repository demonstrate how to implement CNN on MCU by using STM32 Cube-AI.

License

Notifications You must be signed in to change notification settings

Szu-Chi/Implement-MNIST-Handwritten-Digit-Classification-on-MCU

Repository files navigation

Implement MNIST Handwritten Digit Classification on MCU

This repository demonstrate how to implement CNN on MCU by using STM32 X-Cube-AI.

Environment
OS Win11
MCU NUCLEO-F411RE
Python 3.9.12
Keras 2.6.0
Tensorflow 2.8.0
X-Cube-AI 7.2.0
IDE VScode, STM32CubeIDE

Workflow:

  1. Using Keras build classification model.
  2. Create STM32 project.
  3. Testing classification performance on MCU

Using Keras build classification model.

python3 train_model.py

image

Model Summary

Layer (type) Output Shape Param #
input_1 (InputLayer) [(None, 28, 28, 1)] 0
conv2d (Conv2D) (None, 8, 8, 8) 208
conv2d_1 (Conv2D) (None, 3, 3, 16) 1168
flatten (Flatten) (None, 144) 0
dense (Dense) (None, 10) 1450

Total params: 2,826
Trainable params: 2,826
Non-trainable params: 0

Create STM32 project.

Step 1 Create New STM32 project:

  1. Select NUCLEO-F411RE
    image
  2. Create STM32 Project
    image

Step 2 Setup STM32 Peripherals:

1. X-Cube-AI

  • Click Software Packs -> Select Components
    image
  • Enable X-CUBE-AI Core
    image
  • Add Network
    • Software Packs -> STMicroelectronics.X-CUBE-AI.7.2.0 -> Add network
    • Change model name to digit_cnn
    • Click Browse button select pre-trained model digit_classifier_CNN.h5
    • Software Packs -> STMicroelectronics.X-CUBE-AI.7.2.0 -> Analyze image
  • Software Packs -> STMicroelectronics.X-CUBE-AI.7.2.0 -> Show graph\
    image

2. Activate TIM11

image

3. Enable Virtual Com Port Global Interrupt

image

4. Enable generate peripheral initalization as a pair of '.c/.h' file per peripheral

image

5. Generate code and Replace Scirpt

  • Core/Inc/main.h
  • Core/Src/main.c
  • Core/Src/stm32f4xx_it.c

6. Upload program to STM32

Testing classification performance on MCU

This repository testing architecture shown as below figure. image

python3 testing_on_mcu.py

Demo Video Link:

  • [Using Keras build classification model]
  • [Create STM32 project]
  • [Testing classification performance on MCU]

Reference:

About

This repository demonstrate how to implement CNN on MCU by using STM32 Cube-AI.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages