Reading handwritten digits
Draw a number from 0 to 9 in the box. A neural network reads it the way my scoresheet app reads the scores, fouls and player numbers written on a paper sheet.
draw280 × 280
probabilitysoftmax(logits)
inferences: 0
How it works
In the app, OpenCV first finds the scoresheet's grid and cuts out each box that holds handwriting. Every box then goes through the same steps you see here:
- Clean up the image. The sheet is black ink on white paper, so the colours are flipped to give the white-on-black digit the network was trained on.
- Crop and centre. The digit is cropped to its ink, shrunk to fit a 20 × 20 box and centred by its weight on a 28 × 28 grid, so a small 7 in a corner looks the same as a large one in the middle.
- Classify. A convolutional neural network (CNN) scans the 784 pixels for strokes, curves and loops and gives a score for each digit from 0 to 9.
- Pick the answer. Softmax turns the scores into probabilities, shown in the chart. The tallest bar is the prediction.
This page uses a small public model trained on MNIST, a set of 70,000 handwritten digits, and runs it in your browser with ONNX Runtime Web. The app uses a CNN I trained in PyTorch, which reaches 97% accuracy on its test set. It needs a browser with WebGPU, such as a recent Chrome or Edge, and loads about 30 MB the first time.