Deep Learning
Intermediate
4.5
Image Classification with Transfer Learning
Reuse a pretrained network to classify your own images with little data.
1h 45m
1 lesson
1.2K students
What You'll Learn
Learning objectives will be added soon.
Tutorial Content
Why transfer learning
Training a vision model from scratch needs huge data and compute. Transfer learning reuses a network pretrained on millions of images and adapts only the final layer to your classes.
import torch, torchvision
model = torchvision.models.resnet18(weights="DEFAULT")
for p in model.parameters():
p.requires_grad = False # freeze the backbone
model.fc = torch.nn.Linear(model.fc.in_features, num_classes) # new headThe recipe
- Load a pretrained backbone and freeze it.
- Replace the classifier head for your number of classes.
- Train just the head on your (small) dataset.
- Optionally unfreeze and fine-tune the top layers with a low learning rate.
You can get strong results with only a few hundred labeled images.
Your Progress
Sign in to track your progress
Tags
Computer Vision
PyTorch
Deep Learning