What it shows
Cheque and form readers recognise handwriting. A small convolutional neural network learns to read digits from the open MNIST data set. The project trains it on a laptop, tests accuracy, studies the errors and builds a web page where a user draws a digit.
The science
A CNN applies small learnable filters across the image that detect edges and strokes, then pooling layers shrink the image and keep strong responses. Later dense layers combine them into ten class scores, and softmax turns them into probabilities. Training adjusts the filter values by gradient descent to reduce cross-entropy loss. A validation set shows when the model begins to overfit.
Materials
Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.
- A laptop with Python 3, TensorFlow or PyTorch, numpy and matplotlib (or Google Colab free tier)
- The MNIST data set (open, built into the libraries)
- Flask or TensorFlow.js for the demo
- A browser with canvas support
- A notebook for the report
Safety
For this project: Training can make a laptop hot for long periods, so keep it ventilated. Save work often.
Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.
All the safety rulesStep by step
12 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.
Load MNIST and show 25 random images with labels to understand the data.
Normalise the pixel values to the range 0 to 1 and split 5,000 images off for validation.
Build a baseline with a single dense layer and record its test accuracy.
Build a CNN with two convolution and pooling layers, a dense layer, dropout and a softmax output.
Train for 10 epochs, plotting training and validation loss and accuracy.
Evaluate on the 10,000 test images and print the confusion matrix.
View 20 misclassified images and write down why a human might also find them hard.
Try data augmentation with small shifts and rotations, and check whether accuracy rises.
Save the model and write an HTML canvas page where the user draws a digit with the mouse.
Resize the drawing to 28 by 28, centre it as MNIST digits are centred and send it to the model.
Test with digits drawn by ten classmates and record the real-world accuracy, which is usually lower.
Write the report on architecture, training curves, confusion matrix, the gap between test and live accuracy and ethics of automatic recognition.
What you should see
The CNN reaches about 98.5 to 99.3 percent accuracy on the MNIST test set compared with about 92 percent for the baseline. Live drawing accuracy is lower, perhaps 85 to 95 percent, until the preprocessing matches the training data.
Viva questions
A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.
1What does a convolution layer do?
It slides small filters over the image to detect local patterns such as edges.
2What is overfitting and how does dropout help?
Overfitting is memorising the training set. Dropout randomly switches off units so the network cannot depend on any one of them.
3Why is live accuracy lower?
Hand-drawn digits differ in thickness and position from the training images.
4What is an epoch?
One full pass of the training set through the network.
Take it further
Collect 500 digits written in Devanagari by classmates and train a model for Hindi numerals.
Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.
