7.7.27. MNIST Image Classification
Edge AI solution for real-time handwritten digit recognition on the MSPM0G5187 microcontroller, using a LeNet-5 CNN to classify single-digit handwritten character images (0-9).
7.7.27.1. Overview
Handwritten digit recognition is a fundamental task for document processing and automation workflows. Manual data entry is slow and error-prone, and traditional template-matching approaches struggle with the natural variability in human handwriting. Edge AI enables robust, real-time recognition directly on resource-constrained microcontrollers, eliminating the need for cloud connectivity.
This example trains and deploys a LeNet-5 convolutional neural network on the classic MNIST dataset to classify grayscale 28x28 images of handwritten digits (0-9) with approximately 99% accuracy.
Application: OCR, document processing, embedded vision, automation
Task Type: Image Classification
Data Type: Grayscale images (28x28 pixels)
7.7.27.2. Key Targets
Real-time classification of handwritten digit images
High accuracy (~99%)
Low memory footprint suitable for MCU deployment
UART-based communication with host GUI for interactive demo
7.7.27.3. System Components
Hardware
MSPM0G5187 microcontroller
UART connection to host PC
Software
Code Composer Studio (CCS) 12.x or later
MSPM0 SDK 2.08.00 or later
7.7.27.4. Running the Example
cd tinyml-modelzoo
.\run_tinyml_modelzoo.bat examples\MNIST_image_classification\config_image_classification_mnist.yaml
cd tinyml-modelzoo
./run_tinyml_modelzoo.sh examples/MNIST_image_classification/config_image_classification_mnist.yaml
7.7.27.5. Dataset
The mnist_image_classification dataset is based on the classic
MNIST dataset, obtained via
torchvision. It contains 28x28 grayscale PNG images across 10 classes
(digits 0-9).
Property |
Value |
|---|---|
Dataset name |
|
Number of classes |
10 (digits 0-9) |
Image size |
28x28 pixels, grayscale |
Image format |
PNG |
Download URL |
7.7.27.6. Feature Extraction
The feature extraction pipeline prepares raw images for inference:
Image Input – Read 28x28 image
Grayscale Conversion – Convert to single-channel grayscale
Resize – Resize to 28x28 (if needed)
Tensor Conversion – Convert to tensor format
Normalization – Normalize with mean=0.1307, scale=0.3081
7.7.27.7. Model Architecture
LeNet-5 (Default)
The classic LeNet-5 CNN architecture is used, with approximately 60,000 parameters.
Input (28x28x1)
+-- Conv1: 6 filters, 5x5
+-- MaxPool: 2x2
+-- Conv2: 16 filters, 5x5
+-- MaxPool: 2x2
+-- FC1: 120 units
+-- FC2: 84 units
+-- Output: 10 classes
7.7.27.8. Training Configuration
Parameter |
Value |
|---|---|
Model |
|
Batch size |
64 |
Learning rate |
0.1 |
Epochs |
14 |
Quantization |
INT8 |
Compilation target |
TI NNC for CPU inference |
7.7.27.9. Expected Results
Metric |
Value |
|---|---|
Accuracy |
~99% |
7.7.27.10. Supported Devices
Device |
Notes |
|---|---|
Primary target |
|
MSPM0G3507 |
Supported |
MSPM0G3519 |
Supported |
MSPM33C32 |
Supported |