# Model answer: feature extraction and fine-tuning

Subject: Deep Learning

Exam: MT2

Reader: https://deep-learning-study-room.vercel.app/#mt2/read/8/mt2-c8-s5

Canonical: https://deep-learning-study-room.vercel.app/read/dl/mt2/section/mt2-c8-s5/

## Question

**Question.** Explain transfer learning for image classification with limited labeled data. Distinguish feature extraction from fine-tuning and describe the training procedure.

## Answer — step by step

Transfer learning reuses knowledge represented by a model trained on a source task to support a related target task. A pretrained CNN can provide useful visual representations, reducing the target data and training effort needed compared with learning all features from random initialization.

![Freezing and fine-tuning differ in whether selected pretrained weights are allowed to update.](https://deep-learning-study-room.vercel.app/assets/figures/v_transfer.svg)

Diagram: Freezing and fine-tuning differ in whether selected pretrained weights are allowed to update.. Labels: Reuse learned features, then adapt the output | Reuse learned features, then adapt the output | Example: start with an image model trained on a large dataset. | New images | Your smaller | labeled dataset | Feature extractor | Pretrained | convolutional layers | New head | Your classes | Feature extraction: freeze the pretrained layers. | Fine-tuning: unfreeze selected layers and train carefully. | Use validation data to choose settings. A small learning rate often helps | preserve useful features.

Freezing and fine-tuning differ in whether selected pretrained weights are allowed to update. Tap the diagram to enlarge.

### Procedure

1. Define the target classes and create separate training, validation and test splits. Prevent duplicate or closely related captures from leaking across splits.

2. Choose a suitable pretrained backbone and apply its required input size and preprocessing.

3. Replace the original classifier with a new head whose output count matches the target classes.

4. Freeze the backbone and train the new head. Only the unfrozen parameters receive optimizer updates.

5. If validation results justify it, unfreeze selected later backbone layers and continue training with a suitably smaller learning rate.

6. Select hyperparameters and checkpoints using validation data. Evaluate the selected model on the held-out test set.

| Feature extraction | Fine-tuning |
| --- | --- |
| Pretrained backbone weights remain fixed | Some or all selected pretrained weights are updated |
| New classifier learns from fixed representations | Representations can adapt to the target task |
| Usually fewer trainable parameters | Usually more trainable parameters and greater risk of overfitting on a small dataset |

The benefit depends on how useful the source features are for the target data. Transfer is not guaranteed to help every unrelated task. For a numerical, count all stored parameters separately from the trainable subset; freezing a layer does not delete its weights.
