Chapter 2 - Image Classification
Chapter 2 - Image Classification
Notes based on
Machine Learning for the Web by YiNing at ITP, NYU,
How to build a Teachable Machine with TensorFlow.js by Nikhil Thorat from Google Brain, PAIR,
and Daniel Shiffman from the Coding Train
cat
bird
deer
dog
truck
Resolution:
800 x 600 x 3 (RGB)
cat 0.82
bird 0.02
AI deer 0.04
Magic dog 0.10
Box truck 0.02
Resolution:
800 x 600 x 3 (RGB)
Grumpy Cat
Maine Coon Bristish Shorthair (Mixed breed)
2012-2019
Galaxy Classification
Person
Horse
This image is free to use under the Pexels license
Background
Horse
Person
Car
Truck
This image is free to use under the Pexels license
Background
Horse
Person
Car
Truck
This image is free to use under the Pexels license
Car
Car Bike
Output: description: There are two cars and a bike on the road
Resolution:
800 x 600 x 3 (RGB)
def classify_image(image):
# some AI magic
return class_label
https://github.com/zalandoresearch/fashion-mnist
10 classes
50k training images (5k per class)
10k testing images (1k per class)
32x32 RGB images
https://www.cs.toronto.edu/~kriz/cifar.html
Aquatic mammals:
beaver, dolphin, otter, seal, whale
Trees:
Maple, oak, palm, pine, willow
https://www.cs.toronto.edu/~kriz/cifar.html
1000 classes
Q: With N examples,
how fast is training?
Q: With N examples,
how fast is training?
A: O(1)
Q: With N examples,
how fast is training?
A: O(1)
Q: With N examples,
how fast is testing?
Q: With N examples,
how fast is training?
A: O(1)
Q: With N examples,
how fast is testing?
A: O(N)
Q: With N examples,
how fast is training?
A: O(1)
Q: With N examples,
how fast is testing?
A: O(N)
x0
The Energy University
Nearest Neighbor Decision Boundaries
x1
Nearest neighbors
in two dimensions
x0
The Energy University
Nearest Neighbor Decision Boundaries
x1
Nearest neighbors
in two dimensions
Background colors
give the category
x
a test point would
be assigned x0
The Energy University
Nearest Neighbor Decision Boundaries
x1
Decision boundary
Nearest neighbors is the boundary
in two dimensions between two
classification regions
Points are training
examples; colors
give training labels
Background colors
give the category
x
a test point would
be assigned x0
The Energy University
Nearest Neighbor Decision Boundaries
x1
Decision boundary
Nearest neighbors is the boundary
in two dimensions between two
classification regions
Points are training
Decision boundaries
examples; colors
can be noisy;
give training labels
affected by outliers
Background colors
give the category
x
a test point would
be assigned x0
The Energy University
Nearest Neighbor Decision Boundaries
x1
Decision boundary
Nearest neighbors is the boundary
in two dimensions between two
classification regions
Points are training
Decision boundaries
examples; colors
can be noisy;
give training labels
affected by outliers
Background colors How to smooth out
give the category decision boundaries?
x
a test point would Use more neighbors!
be assigned x0
The Energy University
K-Nearest Neighbors Instead of copying label from nearest neighbor,
take majority vote from K closest points
K=1 K=3
K=1 K=3
K=1 K=3
K=1
Example:
Compare
research
papers using
tf-idf similarity
http://www.arxiv-sanity.com/search?q=mesh+r-cnn
http://vision.stanford.edu/teaching/cs231n-demos/knn/
Your dataset
Your dataset
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
Your dataset
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!
(*) Subject to many technical conditions. Only continuous functions on a compact domain; need to make assumptions about spacing of training points; etc.
(*) Subject to many technical conditions. Only continuous functions on a compact domain; need to make assumptions about spacing of training points; etc.
(*) Subject to many technical conditions. Only continuous functions on a compact domain; need to make assumptions about spacing of training points; etc.
(*) Subject to many technical conditions. Only continuous functions on a compact domain; need to make assumptions about spacing of training points; etc.
(*) Subject to many technical conditions. Only continuous functions on a compact domain; need to make assumptions about spacing of training points; etc.
Original image is
(all 3 images have same L2 distance to the one on the left)
CC0 public domain
Devlin et al, “Exploring Nearest Neighbor Approaches for Image Captioning”, 2015
Devlin et al, “Exploring Nearest Neighbor Approaches for Image Captioning”, 2015