Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Project

Stage 3 project: Image classifier

Start after Part 12

Stage 3

Everything from Stage 3 in one build: a CNN, a real train/validation/test split, early stopping that restores the best weights, and a saved checkpoint.

Time: ~3 hours if you build it yourself (recommended). Run the reference version: .venv/bin/python stage-3-deep-learning/project-image-classifier/image_classifier.py

Core (build this)

  1. The digits images reshaped to (N, 1, 8, 8), split 60/20/20 train/val/test.
  2. The Part 12 CNN (two conv blocks, ~10k parameters).
  3. The five-line loop (Part 10) with per-epoch validation loss.
  4. Early stopping with patience 5, restoring the best epoch's weights (Part 11).
  5. A checkpoint file with the state_dict, best epoch and val loss — then ONE test-set evaluation.

Stretch

  • Add data augmentation (random one-pixel shifts of training images — Part 12's exercise 2 shows why) and a learning-rate schedule.
  • Print a confusion matrix of the test errors (Part 6's tool) and look at which digits confuse.

Production level

  • Serve the checkpoint behind an API that accepts an 8×8 image and returns the top-3 classes with probabilities (Track A shows the FastAPI pattern).

What "done" looks like

Output of the reference run:

early stop at epoch 24; best epoch 19 (val loss 0.121)
test accuracy: 0.964
parameters: 9930
checkpoint saved: checkpoint.pt

Search the guide