Model Pipeline - Fine-tuning strategy
This pipeline shows how a pre-trained model is adapted to a new task by fine-tuning. We start with a model trained on a large dataset, then adjust its weights slightly using new task data to improve performance.
Jump into concepts and practice - no test required
This pipeline shows how a pre-trained model is adapted to a new task by fine-tuning. We start with a model trained on a large dataset, then adjust its weights slightly using new task data to improve performance.
Loss
1.2 |*
1.0 | *
0.8 | *
0.6 | *
0.4 | *
0.2 | *
+--------
1 3 5 10
Epochs| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 1.2 | 0.55 | Training only final layer starts with moderate loss and accuracy |
| 3 | 0.8 | 0.70 | Loss decreases and accuracy improves as final layer learns |
| 5 | 0.6 | 0.78 | Final layer training converges with good accuracy |
| 6 | 0.58 | 0.80 | Unfreeze last layers and continue training with low learning rate |
| 8 | 0.45 | 0.85 | Fine-tuning improves model performance further |
| 10 | 0.40 | 0.88 | Loss decreases steadily, accuracy reaches high level |
param.requires_grad = False freezes a layer so it won't update during training.print(sum(p.requires_grad for p in model.parameters()))?
for param in model.parameters():
param.requires_grad = False
for param in model.classifier.parameters():
param.requires_grad = True
print(sum(p.requires_grad for p in model.parameters()))p.requires_grad counts how many parameters are trainable. Since only model.classifier parameters are True, the sum equals their count.requires_grad = False, gradients won't be computed and weights won't update, causing no loss change.