Case study 06

MNIST CNN

A PyTorch CNN that reads your handwriting live, running in the browser through ONNX.

Loading model
Prediction-
  • 00.0%
  • 10.0%
  • 20.0%
  • 30.0%
  • 40.0%
  • 50.0%
  • 60.0%
  • 70.0%
  • 80.0%
  • 90.0%

PyTorch CNN exported to ONNX, running in your browser.

Overview

A convolutional neural network trained from scratch in PyTorch on the MNIST handwritten digit dataset, then exported to ONNX so it can run anywhere without PyTorch.

Draw a digit on the pad and the model classifies it as you draw, showing its confidence for every class from 0 to 9. I trained it alongside a plain MLP baseline to compare how much convolution helps on image data.

What it does

How it works

  1. 01Train the CNN in PyTorch on MNIST with inputs normalised to [-1, 1].
  2. 02Export the trained weights to ONNX.
  3. 03In the browser, crop the drawing to its bounding box and scale it into 20x20.
  4. 04Centre it on a 28x28 canvas and normalise it the same way as in training.
  5. 05Run the model with ONNX Runtime Web and softmax the logits into confidences.

Stack

More projects

Work with me