6.s093’visual’recogni4on’through’...

39
6.S093 Visual Recogni4on through Machine Learning Compe44on Image by kirkh.deviantart.com Joseph Lim and Aditya Khosla Acknowledgment: Many slides from David Sontag and Machine Learning Group of UT Aus4n

Upload: others

Post on 11-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

6.S093  Visual  Recogni4on  through  Machine  Learning  Compe44on  

   

Image by kirkh.deviantart.com

Joseph  Lim  and  Aditya  Khosla    

Acknowledgment:  Many  slides  from  David  Sontag  and  Machine  Learning  Group  of  UT  Aus4n  

Page 2: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

What is Machine Learning???

Page 3: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

What is Machine Learning??? According to the Wikipedia, Machine learning concerns the construction and study of systems that can learn from data.

Page 4: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

What  is  ML?  

•  Classifica4on  – From  data  to  discrete  classes  

Page 5: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

What  is  ML?  

•  Classifica4on  – From  data  to  discrete  classes  

•  Regression  – From  data  to  a  con4nuous  value  

Page 6: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

What  is  ML?  

•  Classifica4on  – From  data  to  discrete  classes  

•  Regression  – From  data  to  a  con4nuous  value  

•  Ranking  – Comparing  items  

Page 7: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

What  is  ML?  

•  Classifica4on  – From  data  to  discrete  classes  

•  Regression  – From  data  to  a  con4nuous  value  

•  Ranking  – Comparing  items  

•  Clustering  – Discovering  structure  in  data  

Page 8: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

What  is  ML?  

•  Classifica4on  – From  data  to  discrete  classes  

•  Regression  – From  data  to  a  con4nuous  value  

•  Ranking  – Comparing  items  

•  Clustering  – Discovering  structure  in  data  

•  Others  

Page 9: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Classifica4on:  data  to  discrete  classes  

•  Spam  filtering  

Spam Regular Urgent

Page 10: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Classifica4on:  data  to  discrete  classes  

•  Object  classifica4on  

Fries Hamburger None

Page 11: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Regression:  data  to  a  value  

•  Stock  market  

Page 12: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Regression:  data  to  a  value  

•  Weather  predic4on  

Page 13: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Clustering:  Discovering  structure  

Set  of  Images  

Page 14: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Clustering

Page 15: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Clustering  

•  Unsupervised  learning  •  Requires  data,  but  NO  LABELS  •  Detect  paTerns  

– Group  emails  or  search  results  – Regions  of  images  

•  Useful  when  don’t  know  what  you’re  looking  for  

Page 16: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Clustering  

•  Basic  idea:  group  together  similar  instances  •  Example:  2D  point  paTerns  

Page 17: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Clustering  

•  Basic  idea:  group  together  similar  instances  •  Example:  2D  point  paTerns  

Page 18: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Clustering  

•  Basic  idea:  group  together  similar  instances  •  Example:  2D  point  paTerns  

Page 19: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Clustering  

•  Basic  idea:  group  together  similar  instances  •  Example:  2D  point  paTerns  

•  What  could  “similar”  mean?  – One  op4on:  small  Euclidean  distance  – Clustering  is  crucially  dependent  on  the  measure  of  similarity  (or  distance)  between  “points”  

Page 20: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

K-­‐Means  •  An  itera4ve  clustering  algorithm  –  Ini4alize:  Pick  K  random  points  as  cluster  centers  

– Alternate:  •  Assign  data  points  to  closest  cluster  center  

•  Change  the  cluster  center  to  the  average  of  its  assigned  points  

– Stop  when  no  points’  assignments  change  

Animation is from Andrey A. Shabalin’s website

Page 21: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

K-­‐Means  •  An  itera4ve  clustering  algorithm  

–  Ini4alize:  Pick  K  random  points  as  cluster  centers  – Alternate:  

•  Assign  data  points  to  closest  cluster  center  

•  Change  the  cluster  center  to  the  average  of  its  assigned  points  

– Stop  when  no  points’  assignments  change  

Page 22: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Proper4es  of  K-­‐means  algorithm  

•  Guaranteed  to  converge  in  a  finite  number  of  itera4ons  

•  Running  4me  per  itera4on:  – Assign  data  points  to  closest  cluster  center  

O(KN)  

– Change  the  cluster  center  to  the  average  of  its  assigned  points  O(N)  

Page 23: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Example:  K-­‐Means  for  Segmenta4on  K=2 Original

Goal of Segmentation is to partition an image into regions each of which has reasonably homogenous visual appearance.

Page 24: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Example:  K-­‐Means  for  Segmenta4on  K=2 K=3 K=10 Original

Page 25: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Picalls  of  K-­‐Means  

•  K-­‐means  algorithm  is  heuris4c  – Requires  ini4al  means  –  It  does  ma2er  what  you  pick!  

•  K-­‐means  can  get  stuck  

K=1 should be better K=2 should be better

Page 26: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Classification

Page 27: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Typical  Recogni4on  System  

features classify +1 bus

-1 not bus

•  Extract  features  from  an  image  •  A  classifier  will  make  a  decision  based  on  extracted  features  

x F(x) y

Page 28: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Typical  Recogni4on  System  

features classify +1 bus

-1 not bus

•  Extract  features  from  an  image  •  A  classifier  will  make  a  decision  based  on  extracted  features  

x F(x) y

Page 29: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Classifica4on  

•  Supervised  learning  •  Requires  data,  AND  LABELS  •  Useful  when  you  know  what  you’re  looking  for  

Page 30: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Linear  classifier  

•  Which  of  these  linear  separators  is  op4mal?  

Page 31: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Maximum  Margin  Classifica4on  •  Maximizing  the  margin  is  good  according  to  intui4on  and  PAC  

theory.  •  Implies  that  only  support  vectors  maTer;  other  training  

examples  are  ignorable.    

Page 32: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Classifica4on  Margin  •  Distance  from  example  xi  to  the  separator  is    •  Examples  closest  to  the  hyperplane  are  support  vectors.    •  Margin  ρ  of  the  separator  is  the  distance  between  support  

vectors.  

wxw br i

T +=

r

ρ

Page 33: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Linear  SVM  Mathema4cally  •  Let  training  set  {(xi,  yi)}i=1..n,  xi  ∈  Rd,  yi  ∈  {-­‐1,  1}  be  separated  by  a  

hyperplane  with  margin  ρ.  Then  for  each  training  example  (xi,  yi):  

•  For  every  support  vector  xs  the  above  inequality  is  an  equality.        Ajer  rescaling  w  and  b  by  ρ/2  in  the  equality,  we  obtain  that  distance  between  each  xs  and  the  hyperplane  is    

•  Then  the  margin  can  be  expressed  through  (rescaled)  w  and  b  as:  

wTxi + b ≤ - ρ/2 if yi = -1 wTxi + b ≥ ρ/2 if yi = 1

w22 == rρ

r = ys (wTxs + b)w

=1w

yi(wTxi + b) ≥ ρ/2 ⇔

Page 34: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Linear  SVMs  Mathema4cally  (cont.)  

•  Then  we  can  formulate  the  quadra.c  op.miza.on  problem:    

Find w and b such that

is maximized

and for all (xi, yi), i=1..n : yi(wTxi + b) ≥ 1

ρ =2w

Find w and b such that

Φ(w) = ||w||2=wTw is minimized

and for all (xi, yi), i=1..n : yi (wTxi + b) ≥ 1

Page 35: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Is  this  perfect?  

Page 36: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Is  this  perfect?  

Page 37: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Soj  Margin  Classifica4on      

•  What  if  the  training  set  is  not  linearly  separable?  •  Slack  variables  ξi  can  be  added  to  allow  misclassifica4on  of  difficult  or  noisy  examples,  resul4ng  margin  called  so;.  

ξi

ξi

Page 38: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Soj  Margin  Classifica4on  Mathema4cally  

•  The  old  formula4on:  

•  Modified  formula4on  incorporates  slack  variables:  

•  Parameter  C  can  be  viewed  as  a  way  to  control  overfilng:    it  “trades  off”  the  rela4ve  importance  of  maximizing  the  margin  and  filng  the  training  data.  

Find w and b such that Φ(w) =wTw is minimized and for all (xi ,yi), i=1..n : yi (wTxi + b) ≥ 1

Find w and b such that Φ(w) =wTw + CΣξi is minimized and for all (xi ,yi), i=1..n : yi (wTxi + b) ≥ 1 – ξi, , ξi ≥ 0

Page 39: 6.S093’Visual’Recogni4on’through’ Machine’Learning’Compe44on’viscomp.csail.mit.edu/resource/slides/lecture4.pdf · lecture4_ml.ppt Author: Joseph Lim Created Date: 1/16/2014

Exercise  

•  Exercise  1.  Implement  K-­‐means  

•  Exercise  2.  Play  with  SVM’s  C-­‐parameter