DRAW A DIGIT IN THE BOX AND HIT PREDICT

MNIST Digit Classifier — Draw → Predict

Train a classifier on MNIST (offline), export to TensorFlow.js, then run inference client-side with an interactive canvas.

TensorFlow.js Netlify static deploy Canvas → 28×28 preprocessing Loss/accuracy plots

What this demo shows

This page is a small end‑to‑end machine learning project: we train a neural network to recognize handwritten digits (0–9) using the MNIST dataset, then we ship the trained model to the browser so anyone can draw a digit and get a prediction instantly.

There are two phases. First is training (done offline in Python): the model learns from thousands of labeled examples and we track how its loss (error) drops and its accuracy rises over epochs. Second is inference (what you’re using here): the model’s weights are frozen, and your drawing is preprocessed into the same 28×28 format MNIST uses, then the model outputs probabilities for each digit.

Our current model is a dense (fully‑connected) network. That means it treats the 28×28 image as a 784‑number vector. A CNN (convolutional neural network) keeps the 2‑D structure longer and learns small reusable “edge/curve” detectors that slide across the image; CNNs usually perform better on images, but a dense model is a clean baseline and still works well for MNIST.

Below, you can (1) review training curves and (2) try the live Draw → Predict interface. After that, the diagrams and PDF provide deeper technical context and implementation notes.

1) Training Metrics

Displays loss/accuracy per epoch from /assets/history.json.

Loss (train vs validation)
Accuracy (train vs validation)

2) Draw → Predict

Draw a digit (0–9). We preprocess to an MNIST-like 28×28 tensor and run inference with frozen weights.

Model: loading…
Preprocess: crop → center → resize → normalize → (optional invert) → predict.
Predicted digit
Confidence
Top-10 probabilities

Neural network diagrams

Two common ways to map a 28×28 digit image to a prediction: a dense network vs a CNN.

Dense neural network diagram
Dense (fully‑connected) network: flatten 28×28 → vector → hidden layers → 10 outputs.
Convolutional neural network diagram
CNN: keep the 2‑D grid longer, learn filters, then flatten → dense → 10 outputs.

Deploy checklist

Train in Python → export to TFJS → deploy static site on Netlify.

  1. Train a Keras model on MNIST in Colab.
  2. Convert to TFJS with tensorflowjs_converter.
  3. Copy model files into /model/.
  4. Copy training curves into /assets/history.json.
  5. Deploy this folder to Netlify (drag-and-drop or Git repo).

Full Write-up (PDF)

This is the long-form project write-up. If it doesn’t render in your browser, use the download link.

File: /assets/mnist_blog_screenshots_combined_no_last.pdf  ·  Open / download
Your browser couldn’t display the PDF inline. Click here to open/download it.