50
6.819 / 6.869: Advances in Computer Vision Learning: Introduction to Machine Learning for Vision Website: http://6.869.csail.mit.edu/fa15/ Instructor: Yusuf Aytar Lecture TR 9:30AM – 11:00AM (Room 34-101)

6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

  • Upload
    others

  • View
    24

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

6.819 / 6.869: Advances in Computer Vision

Learning:Introduction to Machine Learning for Vision

Website:

http://6.869.csail.mit.edu/fa15/

Instructor: Yusuf Aytar

Lecture TR 9:30AM – 11:00AM (Room 34-101)

Page 2: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Key Concepts

Pattern, Category/Class, Instance, Generalization, Classification

Feature space, Objective function, Regularization, Loss Function, OptimizationClassification

Concepts

Support Vector Machines

Page 3: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Where is the bottle ?

Page 4: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

4

Where is Waldo ?

Page 5: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Task: find the most similar patch in a second image

Find the same patch

Page 6: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

?

Page 7: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

?

Page 8: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Computers are good with patterns and

We are good with categories

Pattern vs Category

… but computers are also getting better with categories

Page 9: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Pattern Category

Patterns have discriminative representations

with less variation

Categories also have discriminative representations,

but with great variations

Oliva & Torralba (2007) TICS

Page 10: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Find a bottle:CategoriesInstances Find these two objects

Instance vs Category

Page 11: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Generalization: Extracting the essence of a concept based on its analysis of similarities from many discrete objects.

http://en.wikipedia.org/wiki/Generalization

Generalization

instances

category

Page 12: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Challenges of Generalization

A successful object category detector should be invariant to changes in illumination, occlusion, background clutter, scale,

viewpoint, deformation and intra-class variance.

Page 13: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Object Instance Detection

Find the Object

illumination, occlusion, background clutter, scale, viewpoint, deformation and intra-class variance.

Which of the invariances below apply for the given object instance detection problem?

Page 14: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Classification vs. Detection

Where is the …? Localize the object.Is this a … image ?

TableKitchen HorseWaldo Car

Detection can be performed through a classifier, i.e. sliding window search

Page 15: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Every training sample is represented as a point in the feature space

Feature Space

green

red+

blue

Page 16: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

SIFT: Scale-Invariant Feature Transform

(Lowe, 1999)

HOG: Histograms of oriented gradients(Dalal & Triggs CVPR 05)

Gist: Grid of gabors

(Oliva & Torralba, 2001)

Example Feature Spaces

Page 17: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Machine Learning Methods

Page 18: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Generative vs Discriminative

• Represent both the data and the labels

• Often, makes use of conditional independence and priors

• Examples• Naïve Bayes classifier• Bayesian network

• Models of data may apply to future prediction problems

• Learn to directly predict the labels from the data

• Often, assume a simple boundary (e.g., linear)

• Examples• Logistic regression• SVM• Boosted decision trees

• Often easier to predict a label from the data than to model the data

Page 19: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Discriminative Models

Source: Vittorio Ferrari, Kristen Grauman, Antonio Torralba, Fei-Fei Li

Page 20: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

• Apply a prediction function to a feature representation of the image to get the desired output:

f( ) = “apple”f( ) = “tomato”f( ) = “cow”

Slide credit: L. Lazebnik

Classification

Page 21: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

y = f(x)

• Training: given a training set of labeled examples {(x1,y1), …, (xN,yN)}, estimate the prediction function f by minimizing the prediction error on the training set

• Testing: apply f to a never before seen test example x and output the predicted value y = f(x)

output prediction function image feature

Slide credit: L. Lazebnik

Classification Formulation

Page 22: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Prediction

Training

Image Features

Testing

Test Image

Learned model

Slide credit: D. Hoiem and L. Lazebnik

Training LabelsTraining

Images

TrainingImage Features

Learned model

Learning Framework

Page 23: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

f(x) = label of the training example nearest to x in the feature space

• All we need is a distance function for our inputs • No training required!

Test example

Training examples

from class 1

Training examples

from class 2

Slide credit: L. Lazebnik

Nearest neighbor classification

Page 24: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

K-Nearest neighbor classification

Test example

Page 25: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

3-Nearest neighbor classification

Test example

Page 26: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

5-Nearest neighbor classification

Test example

Simple, a good one to try first

Page 27: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Binary classification can be viewed as the task of separating classes in feature space:

wTx + b = 0

wTx + b < 0wTx + b > 0

f(x) = sign(wTx + b)

Linear Classifiers: Perceptron

Page 28: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Linear Classifiers

A B C

Which one is a better classifier?

f(xi) = sign( )

Page 29: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Which one is a better classifier?

Linear Classifiersf(xi) = sign( )

Page 30: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Support Vector Machines (Intuition)

Page 31: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

■ The linear discriminant function (classifier) with the maximum margin is the best

■ Margin is defined as the width that the boundary could be increased by before hitting a data point

■ Why it is the best? • Robust to outliners and thus

strong generalization ability

“safe zone”Margin

x1

x2

denotes +1

denotes -1

Support Vector Machines

Slide Credit: Jinwei Gu

Page 32: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

■ Given a set of data points:

■ With a scale transformation on both w and b, the above is equivalent to

For 1, 0

For 1, 0

Ti i

Ti i

y by b= + + >

= − + <

w x

w x

, where

For 1, 1

For 1, 1

Ti i

Ti i

y by b= + + ≥

= − + ≤ −

w x

w x

“safe zone”Margin

x1

x2

denotes +1

denotes -1{( , )}, 1, 2, ,i iy i n=x !…

Support Vector Machines

Slide Credit: Jinwei Gu

Page 33: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Loss Function (Hinge Loss)Regularizer

Support Vector Machines

Page 34: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Loss Function (Hinge Loss)Regularizer

Support Vector Machines

Objective Function

y = sign( )Prediction Function Learning: Convex Optimization

gradient

objective (energy)

Page 35: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

• Datasets that are linearly separable work out great:

0 x

Slide credit: Andrew Moore

Non-Linear SVMs

0 x

• But what if the dataset is just too hard?

0 x

x2

• We can map it to a higher-dimensional space:

Page 36: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Φ: x → φ(x)

• General idea: the original input space can always be mapped to some higher-dimensional feature space where the training set is separable:

Slide credit: Andrew Moore

Non-Linear SVMs

Page 37: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

• Consider the mapping ),()( 2xxx =ϕ

22

2222

),(),(),()()(yxxyyxK

yxxyyyxxyx

+=

+=⋅=⋅ϕϕ

x2

Non-Linear Kernel: Example

Page 38: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

• The kernel trick: instead of explicitly computing the lifting transformation φ(x), define a kernel function K such that K(xi , xj) = φ(xi ) · φ(xj)

• This gives a nonlinear decision boundary in the original feature space:

bKybyi

iiii

iii +=+⋅ ∑∑ ),()()( xxxx αϕϕα

C. Burges, A Tutorial on Support Vector Machines for Pattern Recognition, Data Mining and Knowledge Discovery, 1998

Non-Linear SVMs

Page 39: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

❑ Linear kernel:

2

2( , ) exp( )2i j

i jKσ

−= −

x xx x

( , ) Ti j i jK =x x x x

( , ) (1 )T pi j i jK = +x x x x

0 1( , ) tanh( )Ti j i jK β β= +x x x x

❑ Polynomial kernel:

❑ Gaussian (Radial-Basis Function (RBF) ) kernel:

❑ Sigmoid:

■ In general, functions that satisfy Mercer’s condition can be kernel functions.

Common Kernel Functions

Page 40: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

1. Pick an image representation (HoG, SIFT+BOW, etc.)2. Pick a kernel function for that representation3. Compute the matrix of kernel values between every pair of

training examples4. Feed the kernel matrix into your favorite SVM solver to obtain

support vectors and weights5. At test time: compute kernel values for your test example and

each support vector, and combine them with the learned weights to get the value of the decision function

Slide credit: L. Lazebnik

Summary: SVMs for image classification

Page 41: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

http://www.mathworks.com/help/stats/svmtrain.html

MATLAB SVM Example

http://www.vlfeat.org/overview/svm.html

Page 42: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

• Unfortunately, there is no “definitive” multi-class SVM formulation

• In practice, we have to obtain a multi-class SVM by combining multiple two-class SVMs

• One vs. others• Training: learn an SVM for each class vs. the others• Testing: apply each SVM to test example and assign to it the

class of the SVM that returns the highest decision value

• One vs. one• Training: learn an SVM for each pair of classes• Testing: each learned SVM “votes” for a class to assign to the

test example

Slide credit: L. Lazebnik

What about multi-class SVMs?

Page 43: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

• Pros• Many publicly available SVM packages (LibSVM, Liblinear,etc):

http://www.kernel-machines.org/software• Kernel-based framework is very powerful, flexible• SVMs work very well in practice, even with very small training

sample sizes

• Cons• No “direct” multi-class SVM, must combine two-class SVMs• Computation, memory

– During training time, must compute matrix of kernel values for every pair of examples

– Learning can take a very long time for large-scale problems

SVMs: Pros and cons

Page 44: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

• How well does a learned model generalize from the data it was trained on to a new test set?

Training set (labels known) Test set (labels unknown)

Slide credit: L. Lazebnik

Generalization

Page 45: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Slide credit: D. Hoiem

Underfitting: model is too “simple” to represent all the relevant class characteristics samples

simple model

preferred model

Overfitting: model is too “complex” and fits irrelevant characteristics (noise) in the data

samples

complex model

preferred model

Overfitting vs Underfitting“Everything should be made as simple as possible, but not simpler.”

Albert Einstein

Page 46: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Traditional Detector Training (Motorbike)

Positive Samples

Negative Samples

Positive HOGs

Negative HOGs

Motorbike Detector

[Dalal et al. CVPR’05][Felzenszwalb et al. CVPR’08]

Training Samples

Feature Extraction (Histogram of

Oriented Gradients)

HOG Features

Linear SVM

Use Case: Linear SVMs over HoG

Page 47: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Linear SVMs over

HoG features

[Dalal &Triggs’05], [Felzenszwalb’08] [Malisiewicz’11]

Exemplar SVM

Training an SVM with a single positive and many negative samples

Use Case: Exemplar SVMs

Page 48: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Another Classifier: Randomized Decision Forests

Shotton et.al., Real-Time Human Pose Recognition in Parts from Single Depth Images, CVPR, 2011

Page 49: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Body Part Classification with Randomized Decision Forests

Shotton et.al., Real-Time Human Pose Recognition in Parts from Single Depth Images, CVPR, 2011

Page 50: 6.819 / 6.869: Advances in Computer Vision6.869.csail.mit.edu/fa15/lecture/6.869-L11-Intro... · Introduction to Machine Learning for Vision ... Another Classifier: Deep Learning

Another Classifier: Deep Learning

Next Lecture …