Deep Learning · MT2 · section
R26 Q7b
R26 selected MT2 practice
Question
Question (10 marks). Explain transfer learning with CNNs and how to adapt a pretrained model to a new image classification task, including an example model.
Answer — step by step
Transfer learning reuses features learned on a source task to solve a related target task. For a small vegetable-image dataset, a pretrained CNN provides a stronger starting point than estimating a very large model entirely from that small dataset.
1. Collect labeled examples with varied lighting, pose and background. Split data so duplicate or near-duplicate photos do not leak across sets. Use independently captured vegetable examples in each split; keep near-duplicates or repeated images of the same item together.
2. Resize images and apply the preprocessing expected by the pretrained model. Use label-preserving augmentation such as small crops, shifts or illumination changes.
3. Load a suitable pretrained CNN, remove its source classification head and attach a new head with one output per required class. For mutually exclusive classes use softmax and categorical cross-entropy.
4. Freeze the convolutional base and train the new head. Frozen parameters still participate in prediction but are not updated in this stage.
5. If validation results justify it, unfreeze selected later layers and fine-tune with a smaller learning rate. Use early stopping and appropriate regularization.
6. Evaluate on a held-out vegetable test set and inspect the confusion matrix and per-class errors. Check which vegetables are confused under different lighting or backgrounds.
Feature extraction keeps the base frozen; fine-tuning updates some pretrained weights. Benefits include reduced target-data requirements and faster useful training. Risks include source-target mismatch and overfitting the small target set. Transfer learning improves the starting point, not a guarantee of perfect recognition.
Concrete example: replace the 1000-class head of a pretrained ResNet with a 10-class vegetable head. Train the new head with the base frozen, then optionally fine-tune late residual blocks at a smaller rate. Input preprocessing must match the pretrained model. The 10 output probabilities sum to 1 for mutually exclusive classes.