Professional Documents
Culture Documents
• Batching & preparing datasets for modelling (making them run fast)
• Fine-tuning your feature extraction model to the beat the DeepFood paper 📈
👩🍳 👩🔬
(cook up lots of code!)
How:
Serial experimentation
Everything you got
Xtra-Large dataset,
xtra-large model
Small dataset,
small model
Being prepared
n s o r 1
Te CPU
[[0, 13, 125…], [[0., 13., 125.…], Tensor 3
[1, 14, 200…], [1., 14., 200.…],
[2, 20, 210…], [2., 20., 210.…], Tensor 2
GPU
…, …, Tensor 1
Being computed on
Source: Page 422 of Hands-On Machine Learning with Scikit-Learn, Keras & TensorFlow Book by Aurélien Géron
What are callbacks?
• Callbacks are a tool which can add helpful functionality to your models during training,
evaluation or inference
Log the performance of multiple models and then view and compare
these models in a visual way on TensorBoard (a dashboard for
TensorBoard tf.keras.callbacks.TensorBoard()
inspecting neural network parameters). Helpful to compare the results
of di erent models on your data.
Save your model as it trains so you can stop training if needed and
Model checkpointing come back to continue o where you left. Helpful if training takes a tf.keras.callbacks.ModelCheckpoint()
long time and can't be done in one sitting.
Leave your model training for an arbitrary amount of time and have it
Early stopping stop training automatically when it ceases to improve. Helpful when tf.keras.callbacks.EarlyStopping()
you've got a large dataset and don't know how long training will take.
ff
ff
What is mixed precision training?
Mixed precision training uses the combination of float32 and float16 data types to speed up
model training (can result in a 3x speed up on modern GPUs).
No mixed precision
With mixed precision
Feature extraction vs. Fine-tuning
Custom final layer
Stays same
gets trained to custom 10 10
data
Top layers get
…
unfrozen and fine-
Layer 235 Layer 235 tuned on custom data
Changes
(unfrozen)
Layer 234 Layer 234
Working architecture
…
(e.g. E cientNet) pre-
trained on ImageNet
Layer 2 Layer 2
Stays same
Bottom layers (ma
(frozen) y)
stay frozen
Input Layer Input Layer
…
…
Fine-t
Might change usual uning
ly req
more d uires
ata th
featur an
Custom dataset (e.g. 10 classes of food) extrac e
tion
…
unfrozen and fine-
Layer 235 Layer 235 tuned on custom data
…
(e.g. E cientNet) pre-
trained on ImageNet
Layer 2 Layer 2
Bottom layers (ma
y)
stay frozen
Input Layer Input Layer
…
…
Fine-t
usual uning
ly req
more d uires
ata th
featur an
extrac e
Custom dataset (e.g. 101 classes of food) tion
Results from ne-tuning 🍔👁 Food Vision Big™ on Food101 dataset using an E cienetNetB0
backbone using a Google Colab Tesla T4 GPU.
fi
ffi
Model we’ve created (for m i x e d p re c i s i on
training)
Input data Model Output
a x a c t iv a t i on
Softm
p e = f l oa t 3 2
with dty
GlobalAvgPool2D
Softmax
101
E cientNetB0 architecture.
Source: https://ai.googleblog.com/2019/05/e cientnet-improving-accuracy-and.html
- c o n n e c t e d
Fully
a s s if ie r l a y e r
(dense) cl
ffi
ffi
(some common)
Wrong label?
i n g c la s s
Co nf u s
Anatomy of a confusion matrix
Confusion Matrix
False positives
Correct predictions
t i v e s 0 1 (true positives,
e g a
False n Predicted Label true negatives)