Professional Documents
Culture Documents
Discussion 2 - Image Classification - Annotated
Discussion 2 - Image Classification - Annotated
Overview
Image Classification : A core task in Computer
Vision
Given : dog, cat, truck, plane, …
Cat
Test Image
56 32 10 18 10 20 24 17 46 12 14 1
𝒅 𝟏 ( 𝑰 𝟏 , 𝑰 𝟐 )=∑ ¿ 𝑰 − 𝑰 ∨¿¿ 𝒅 𝟏 ( 𝑰 𝟏 , 𝑰 𝟐 )=
𝒑
𝒑
𝟏
𝒑
𝟐
√ ∑
𝒑
( 𝑰
𝒑
𝟏 −𝑰
𝒑𝟐
)
𝟐
𝒅 𝟏 ( 𝑰 𝟏 , 𝑰 𝟐 )=∑ ¿ 𝑰 − 𝑰 ∨¿¿ 𝒅 𝟏 ( 𝑰 𝟏 , 𝑰 𝟐 )=
𝒑
𝒑
𝟏
𝒑
𝟐
√ ∑
𝒑
( 𝑰
𝒑
𝟏 −𝑰
𝒑𝟐
)
𝟐
𝒅 𝟏 ( 𝑰 𝟏 , 𝑰 𝟐 )=∑ ¿ 𝑰 − 𝑰 ∨¿¿ 𝒅 𝟏 ( 𝑰 𝟏 , 𝑰 𝟐 )=
𝒑
𝒑
𝟏
𝒑
𝟐
√ ∑
𝒑
( 𝑰
𝒑
𝟏 −𝑰
𝒑𝟐
)
𝟐
Very problem-dependent.
Must try them all out and see what works best.
Idea #2: Split data into train and test, choose BAD: No idea how algorithm
hyperparameters that work best on test data will perform on new data
Train Test
Idea #3: Split data into train, val, and test; choose
hyperparameters on val and evaluate on test Better!
Dimensions = 1
Points = 4
moodle.skylightmyanmar.com 32
Parametric Approach : Linear Classifier
𝒇
3027x1
𝑾
Image 𝒇 ( 𝒙 ,𝑾 )=𝑾 𝒙
10x1 10x3027 𝒙
𝒇 (𝒙 ,𝑾 ) 10 numbers giving
class scores
𝒇 (𝒙 ,𝑾 ) 10 numbers giving
class scores
56
0.2 -0.5 0.1 2.0
1.1 -96.8 Cat score
56 231
231 3.2 437.9 Dog score
1.5 1.3 2.1 0.0 + =
24 2
0.0 0.25 0.2 -0.3 24 -1.2 61.95 Ship score
Input Image 2
W b
x
56 -96.8
0.2 -0.5 0.1 2.0 1.1 Cat score
56 231
231 437.9 Dog score
1.5 1.3 2.1 0.0 3.2 =
24 2
0.0 0.25 0.2 -0.3 -1.2 24 61.95 Ship score
Input Image
W b 2
Bias Trick 1
x
Slide Credit : Stanford CS231n
moodle.skylightmyanmar.com 36
Interpreting a Linear Classifier 56 231
24 2
Deer
Slide Credit : Stanford CS231n
moodle.skylightmyanmar.com 38
Hard cases for Linear Classifier
Class 1:
Class 1:
0 <= L2 distance <= 2
Red Region
Class 2:
Class 2:
4 <= L2 distance <= 6
Blue Region
moodle.skylightmyanmar.com 39
Linear Classifier: Three Viewpoints
Algebraic Viewpoint Visual Viewpoint Geometric Viewpoint
Hyperplanes
𝒇 ( 𝒙 ,𝑾 )=𝑾 𝒙+𝒃 One template per class
Optimization