๐ŸŽ™ Free live masterclass ยท Sun, 29 Nov, 7:00 pm IST ยท Java Full Stack roadmap Register free โ†’
Skills101

Handwritten digit recogniser (CNN)

Train a CNN to read handwritten digits at 99% accuracy, then draw your own digits in a web canvas to test it.

Beginnerโฑ 6โ€“10 hours๐Ÿชœ 7 stepsPythonPyTorch or TensorFlow/KerasMNIST

What you'll learn

  • โ—†Convolutional neural networks
  • โ—†Training loops, loss and accuracy curves
  • โ—†Overfitting and dropout

What you'll build

  • โœ“CNN trained on MNIST
  • โœ“Training and validation curves
  • โœ“Confusion matrix of mistakes
  • โœ“Draw-a-digit demo

Step-by-step guide

  1. 1

    Load MNIST

    torchvision.datasets.MNIST (or keras.datasets.mnist); normalise pixels to 0โ€“1.

  2. 2

    Baseline

    Start with a simple dense network to see ~97% accuracy.

  3. 3

    CNN

    Two Conv2d + ReLU + MaxPool blocks, then Dropout and a Linear layer to 10 classes.

  4. 4

    Train

    Adam optimiser, cross-entropy loss, 5โ€“10 epochs; plot train vs validation accuracy.

  5. 5

    Inspect errors

    Show the misclassified test images; most are genuinely ambiguous.

  6. 6

    Save

    torch.save(model.state_dict()) or model.save("mnist.keras").

  7. 7

    Demo

    A Streamlit app with a drawable canvas (streamlit-drawable-canvas); resize to 28ร—28, invert colours to match MNIST, predict.

๐Ÿš€ Make it stand out

  • +Data augmentation
  • +Train on Devanagari digits
  • +Export to ONNX and run in the browser