Professional Documents
Culture Documents
https://www.github.com/mrdbourke/pytorch-deep-learning/discussions
“What is transfer learning?”
Surely someone has spent the time crafting the right model for the job…
Example transfer learning use cases
Computer vision
Model learns patterns/weights from similar problem space Patterns get used/tuned to speci c problem
fi
“Why use transfer learning?”
Why use transfer learning?
• Can leverage an existing neural network architecture proven to work on problems similar to our
own
• Can leverage a working network architecture which has already learned patterns on similar
data to our own (often results in great results with less data)
Pretrained E cientNet
Learn patterns in a Extract/tune patterns/weights
architecture (already works Model performs better
wide variety of images to suit our own problem
really well on computer vision than from scratch
(using ImageNet) (FoodVision Mini)
tasks)
ffi
Improving a model
Method to improve a model
What does it do?
(reduce over tting)
Not all data samples are created equally. Removing poor samples
Better data from or adding better samples to your dataset can improve your
model’s performance.
PyTorch domains libraries (torchvision, torchtext, torchaudio, Torch Image Models (timm library).
torchrec). Source: https://pytorch.org/vision/stable/models.html Source: https://github.com/rwightman/pytorch-image-models
👩🍳 👩🔬
(we’ll be cooking up lots of code!)
How:
Let’s code!
Original Model vs. Feature Extraction
Output layer(s) gets trained
ImageNet has Changes on new data
1000 classes Output Layer (shape = 1000) 3
…
Layer 235 Layer 235
…
(original model layers
(e.g. E cientNet) don’t update during training)
Layer 2 Layer 2
…
Changes
Large dataset (e.g. ImageNet) Di erent dataset (e.g. 3 classes of food 🍕🥩🍣)
…
Layer 235 Layer 235 Layer 235
Changes
(unfrozen)
Layer 234 Stays same Layer 234 Layer 234
(frozen)
…
…
Layer 2 Layer 2 Layer 2
Stays same
(frozen)
Input Layer Input Layer Input Layer
…
…
Fine-t
Changes Might change usual uning
ly req
more d uires
ata th
featur an
Large dataset (e.g. ImageNet) Di erent dataset (e.g. 3 classes of food 🍕🥩🍣) extrac e
tion
Take the underlying patterns (also Helpful if you have a small amount of custom
Most of the layers in the original
called weights) a pretrained model data (similar to what the original model was
Feature extraction has learned and adjust its outputs
model remain frozen during training
trained on) and want to utilise a pretrained model
(only the top 1-3 layers get updated).
to be more suited to your problem. to get better results on your speci c problem.
🥩
🍣
3
🍕
E cientNetB0 architecture. Source: https://ai.googleblog.com/2019/05/e cientnet-improving-accuracy-and.html
EfficientNetB0 Backbone si f i e r l a y e r
Linear clas
(torchvision.models.efficientnet_b0) n . L i n e a r )
(torch.n
ffi
ffi
EfficientNet feature extractor
EfficientNetB0 Backbone
(torchvision.models.efficientnet_b0(prertained=True)
Extracts features
from image
Same
Changed