Adapt a pretrained image model with transfer learning

8 steps · about 3 h 5 min · Intermediate

  1. Know what the convolutional layers have learned (article, Stanford CS231n, 35 min)

    A clear picture of convolution, pooling and depth explains why early layers transfer well to a new image task.

  2. Decide how much of the network to retrain (article, Stanford CS231n, 15 min)

    Dataset size and similarity decide whether to freeze the backbone or fine-tune it; settle that before writing code.

  3. Load pretrained weights with their own preprocessing (reference, PyTorch, 15 min)

    Each weight set ships with the resize and normalisation it was trained on; using them avoids a silent accuracy loss.

  4. Augment a small training set (tutorial, PyTorch, 20 min)

    Random crops, flips and colour changes stretch a small dataset, but only on the training split.

  5. Fine-tune and feature-extract on a real dataset (tutorial, PyTorch, 45 min)

    Run both strategies side by side on the same images and compare their accuracy and training time.

  6. Checkpoint the best epoch (tutorial, PyTorch, 15 min)

    Keep the weights from the epoch with the best validation score instead of whatever the last epoch produced.

  7. Find the classes the model confuses (reference, scikit-learn, 15 min)

    A confusion matrix on held-out images shows which classes need more data or clearer labels.

  8. Debug training the disciplined way (blog, Andrej Karpathy, 25 min)

    End with a practical checklist for overfitting a single batch, checking inputs and changing one thing at a time.