Project
Stage 3 project: Image classifier
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)
- The digits images reshaped to
(N, 1, 8, 8), split 60/20/20 train/val/test. - The Part 12 CNN (two conv blocks, ~10k parameters).
- The five-line loop (Part 10) with per-epoch validation loss.
- Early stopping with patience 5, restoring the best epoch's weights (Part 11).
- 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