Image Classification with Deep Learning
Image Classification with Deep Learning
Today:
● The image classification task
● Two basic data-driven approaches to image classification
○ K-nearest neighbor and linear classifier
cat
This image is CC0 1.0 public domain This image is CC0 1.0 public domain This image is CC0 1.0 public domain This image is CC0 1.0 public domain
This image is CC0 1.0 public domain This image is CC0 1.0 public domain
This image by Umberto Salvagnin This image by sare bear is This image by Tom Thai is
This image by Umberto Salvagnin
is licensed under CC-BY 2.0 licensed under CC-BY 2.0 licensed under CC-BY 2.0
is licensed under CC-BY 2.0
Image source:
[Link]
?utm_source=linkedin_share&utm_medium=member_desktop_web
?
John Canny, “A Computational Approach to Edge Detection”, IEEE TPAMI 1986
Memorize all
data and labels
query data
Distance Metric
L1 distance:
add
Q: With N examples,
how fast are training
and prediction?
A good implementation:
[Link]
1-nearest neighbor
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 - 26 April 6, 2023
K-Nearest Neighbors
Instead of copying label from nearest neighbor,
take majority vote from K closest points
K=1 K=1
[Link]
Very problem/dataset-dependent.
Must try them all out and see what works best.
train
train
train
train
Never do this!
train
Useful for small datasets, but not used too frequently in deep learning
Alex Krizhevsky, “Learning Multiple Layers of Features from Tiny Images”, Technical Report, 2009.
Alex Krizhevsky, “Learning Multiple Layers of Features from Tiny Images”, Technical Report, 2009.
(All three images on the right have the same pixel distances to the one on the left)
Dimensions = 2
Points = 42
Dimensions = 1
Points = 4
Image
10 numbers giving
f(x,W) class scores
Array of 32x32x3 numbers
(3072 numbers total)
W
parameters
or weights
Image
f(x,W) = Wx
10 numbers giving
f(x,W) class scores
Array of 32x32x3 numbers
(3072 numbers total)
W
parameters
or weights
Image
f(x,W) = Wx
10x1 10x3072
10 numbers giving
f(x,W) class scores
Array of 32x32x3 numbers
(3072 numbers total)
W
parameters
or weights
Image
f(x,W) = Wx + b 10x1
10x1 10x3072
10 numbers giving
f(x,W) class scores
Array of 32x32x3 numbers
(3072 numbers total)
W
parameters
or weights
Linear
classifiers
56
56 231
231
24 2
24
Input image
2
56
0.2 -0.5 0.1 2.0 1.1 -96.8 Cat score
56 231
231
24 2
1.5 1.3 2.1 0.0
24
+ 3.2
= 437.9 Dog score
f(x,W) = Wx + b
Plot created using Wolfram Cloud Cat image by Nikita is licensed under CC-BY 2.0
Cat image by Nikita is licensed under CC-BY 2.0; Car image is CC0 1.0 public domain; Frog image is in the public domain
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -60 April 6, 2023
Suppose: 3 training examples, 3 classes.
With some W the scores are:
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -61 April 6, 2023
Suppose: 3 training examples, 3 classes. A loss function tells how good
With some W the scores are: our current classifier is
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -62 April 6, 2023
Suppose: 3 training examples, 3 classes. A loss function tells how good
With some W the scores are: our current classifier is
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -63 April 6, 2023
Suppose: 3 training examples, 3 classes. A loss function tells how good
With some W the scores are: our current classifier is
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -64 April 6, 2023
Suppose: 3 training examples, 3 classes. Multiclass SVM loss:
With some W the scores are:
Given an example
where is the image and
where is the (integer) label,
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -65 April 6, 2023
Suppose: 3 training examples, 3 classes. Interpreting Multiclass SVM loss:
With some W the scores are:
Given an example
where is the image and
Loss
where is the (integer) label,
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -66 April 6, 2023
Suppose: 3 training examples, 3 classes. Interpreting Multiclass SVM loss:
With some W the scores are:
Given an example
where is the image and
Loss
where is the (integer) label,
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -67 April 6, 2023
Suppose: 3 training examples, 3 classes. Interpreting Multiclass SVM loss:
With some W the scores are:
Given an example
where is the image and
Loss
where is the (integer) label,
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -68 April 6, 2023
Suppose: 3 training examples, 3 classes. Multiclass SVM loss:
With some W the scores are:
Given an example
where is the image and
where is the (integer) label,
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -69 April 6, 2023
Suppose: 3 training examples, 3 classes. Multiclass SVM loss:
With some W the scores are:
Given an example
where is the image and
where is the (integer) label,
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -70 April 6, 2023
Suppose: 3 training examples, 3 classes. Multiclass SVM loss:
With some W the scores are:
Given an example
where is the image and
where is the (integer) label,
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -71 April 6, 2023
Suppose: 3 training examples, 3 classes. Multiclass SVM loss:
With some W the scores are:
Given an example
where is the image and
where is the (integer) label,
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -72 April 6, 2023
Suppose: 3 training examples, 3 classes. Multiclass SVM loss:
With some W the scores are:
Given an example
where is the image and
where is the (integer) label,
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -75 April 6, 2023
Suppose: 3 training examples, 3 classes. Multiclass SVM loss:
With some W the scores are:
Given an example
where is the image and
where is the (integer) label,
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -76 April 6, 2023
Suppose: 3 training examples, 3 classes. Multiclass SVM loss:
With some W the scores are:
Given an example
where is the image and
where is the (integer) label,
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -79 April 6, 2023
Softmax classifier
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -80 April 6, 2023
Softmax Classifier (Multinomial Logistic Regression)
Want to interpret raw classifier scores as probabilities
cat 3.2
car 5.1
frog -1.7
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -81 April 6, 2023
Softmax Classifier (Multinomial Logistic Regression)
Want to interpret raw classifier scores as probabilities
Softmax
Function
cat 3.2
car 5.1
frog -1.7
Fei-Fei Li, Yunzhu Li, Ruohan Gao Lecture 2 -82 April 6, 2023
Softmax Classifier (Multinomial Logistic Regression)
Want to interpret raw classifier scores as probabilities
Softmax
Function
Probabilities
must be >= 0
cat 3.2
car 5.1
frog -1.7
cat 3.2
car Q1: What is the min/max possible softmax loss Li?
5.1
frog -1.7 Q2: At initialization all sj will be approximately equal;
what is the softmax loss Li, assuming C classes?
cat 3.2
car Q2: At initialization all s will be
5.1 approximately equal; what is the loss?
frog -1.7 A: -log(1/C) = log(C),
If C = 10, then Li = log(10) ≈ 2.3
- Regularization
- Optimization