Computer Vision · Intermediate level

Intermediate level · Module 8: Transfer Learning · Lesson 1 of 3

Feature Extraction and Fine-Tuning

Learners adapt a pretrained MobileNet or ResNet to a new image task, first by training only a new classifier head, then by fine-tuning deeper layers.

In this lesson you will

  • Replace and train a classifier head on a pretrained backbone
  • Fine-tune deeper layers with a lower learning rate

Key concepts

pretrained weightsfrozen backbone (requires_grad=False)new classifier headfine-tuningdifferential learning rates

The lesson

A network pretrained on a large image dataset has learned general features (edges, textures, shapes) that help on new tasks. Load one with torchvision.models.mobilenet_v3_small(weights='DEFAULT'), replace the final layer with one that has your number of classes, and freeze the rest.

Feature extraction trains only the new head, which is fast and works on a CPU with a few hundred images. Fine-tuning then unfreezes some later layers and trains them with a small learning rate (for example ten times smaller than the head's), which usually improves accuracy further.

Use the preprocessing that matches the pretrained weights (weights.transforms()); otherwise inputs are scaled differently from what the model expects.

Step by step

  1. Load a pretrained MobileNetV3 and replace its classifier.
  2. Freeze the backbone and train the head on the produce dataset.
  3. Unfreeze the last blocks and fine-tune with a lower learning rate.
  4. Compare accuracy with the Beginner classical pipeline.

Practice activity

Train a transfer-learning classifier for the Beginner project categories and compare it with the classical pipeline.

Expected result: A clear accuracy improvement, measured on the same test set, with training times.

Check your understanding

  1. Why use the pretrained model's own preprocessing transforms?

    Show answer

    So that inputs are scaled the way the model expects.

  2. Why use a smaller learning rate when fine-tuning?

    Show answer

    To adjust the pretrained features gently without destroying them.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.