machine learning for signal
play

Machine Learning for Signal Processing Eigenfaces and - PowerPoint PPT Presentation

Machine Learning for Signal Processing Eigenfaces and Eigenrepresentations Class 6. 17 Sep 2013 Instructor: Bhiksha Raj 17 Sep 2013 11-755/18-797 1 Administrivia Project teams? By the end of the month.. Project proposals?


  1. Error from approximating a single vector v vv T x y x-vv T x x x • Error from projecting a vector x on to a vector 2 onto a unit vector v   T ( x ) x vv x e        T       T T T T T T e ( x ) x vv x x vv x x x vv x vv x     T T T T T T T x x x vv x x vv x x vv x   T T T e ( x ) x x x vv x 17 Sep 2013 11-755/18-797 29

  2. Error from approximating a single vector v vv T x y x-vv T x x x e(x) = x T x – x T v . v T x Length of projection This is the very familiar pythogoras ’ theorem!! 17 Sep 2013 11-755/18-797 30

  3. Error for many vectors v y x   • Error for one vector: T T T e ( x ) x x x vv x • Error for many vectors            T T T T T T x x x vv x E e ( x ) x x x vv x i i i i i i i i i i i i i • Goal: Estimate v to minimize this error! 17 Sep 2013 11-755/18-797 31

  4. Error for many vectors v y x   • Total error:   T T T x x x vv x E i i i i i i • Add constraint: v T v = 1 • Constrained objective to minimize:          T T T T x x x vv x v v 1 E i i i i i i 17 Sep 2013 11-755/18-797 32

  5. Two Matrix Identities • Derivative w.r.t v T d v v  2 v d v T T x vv x d  T 2 xx v v d 17 Sep 2013 11-755/18-797 33

  6. Minimizing error v y     x      T T T T E x x x vv x v v 1 i i i i i i • Differentiating w.r.t v and equating to 0         T 2 x x v 2 v 0     T x x v v i i i i   i i 17 Sep 2013 11-755/18-797 34

  7. The correlation matrix        T x x v v i i   i • The encircled term is the correlation matrix    T T   x x XX R  i i X x x ... x 1 2 N i X T = Transposed X = Data Matrix Data Matrix = Correlation 17 Sep 2013 11-755/18-797 35

  8. The best “basis” v y x • The minimum-error basis is found by solving   Rv v • v is an Eigen vector of the correlation matrix R –  is the corresponding Eigen value 17 Sep 2013 11-755/18-797 36

  9. What about the total error?     T T T E x x x vv x i i i i i i • x T v = v T x (inner product)           T T T   x x v x x v T T T E x x v x x v i i i i i i i i   i i i i            T T T T T T E x x v Rv x x v v x x v v i i i i i i i i i     T x x E i i i 17 Sep 2013 11-755/18-797 37

  10. Minimizing the error     T • The total error is E x x i i i • We already know that the optimal basis is an Eigen vector • The total error depends on the negative of the corresponding Eigen value • To minimize error, we must maximize  • i.e. Select the Eigen vector with the largest Eigen value 17 Sep 2013 11-755/18-797 38

  11. The typical face The typical face • Compute the correlation matrix for your data – Arrange them in matrix X and compute R = XX T • Compute the principal Eigen vector of R – The Eigen vector with the largest Eigen value • This is the typical face 17 Sep 2013 11-755/18-797 39

  12. With many typical faces M = W Typical faces V U = Approximation • Approximate every face f as f = w f,1 V 1 + w f,2 V 2 +... + w f,k V k • Here W, V and U are ALL unknown and must be determined – Such that the squared error between U and M is minimum 17 Sep 2013 11-755/18-797 40

  13. With multiple bases • Assumption: all bases v 1 v 2 v 3 .. are unit length • Assumption: all bases are orthogonal to one another: v i T v j = 0 if i != j – We are trying to find the optimal K-dimensional subspace to project the data – Any set of vectors in this subspace will define the subspace – Constraining them to be orthogonal does not change this • I.e. if V = [ v 1 v 2 v 3 … ], V T V = I – Pinv( V ) = V T • Projection matrix for V = V Pinv( V ) = VV T 17 Sep 2013 11-755/18-797 41

  14. With multiple bases Represents a V K-dimensional subspace VV T x y x-VV T x x x • Optimal projection for a vector  ˆ T x VV x  ˆ   • Error vector = T x x x VV x • Error length =   T T T e ( x ) x x x VV x 17 Sep 2013 11-755/18-797 42

  15. With multiple bases V y x   T T T • Error for one vector: ( x ) x x x VV x e • Error for many vectors     T T T E x x x VV x i i i i i i • Goal: Estimate V to minimize this error! 17 Sep 2013 11-755/18-797 43

  16. Minimizing error • With regularization V T V = I , objective to minimize          L  T T T T x x x VV x V V I E trace i i i i i i – Note: now L is a diagonal matrix – The regularization simply ensures that v T v = 1 for every basis • Differentiating w.r.t V and equating to 0      L     L T 2 x x V 2 V 0 RV V i i   i 17 Sep 2013 11-755/18-797 44

  17. Finding the optimal K bases  L RV V • Compute the Eigendecompsition of the correlation matrix • Select K Eigen vectors • But which K ? K      T x x E • Total error = i i j  i j 1 • Select K eigen vectors corresponding to the K largest Eigen values 17 Sep 2013 11-755/18-797 45

  18. Eigen Faces! • Arrange your input data into a matrix X • Compute the correlation R = XX T • Solve the Eigen decomposition: RV = L V • The Eigen vectors corresponding to the K largest eigen values are our optimal bases • We will refer to these as eigen faces. 17 Sep 2013 11-755/18-797 46

  19. How many Eigen faces 300x10000 10000x10000 10000x300 M = Data Matrix M T = Transposed Data Matrix = Correlation • How to choose “K” (number of Eigen faces) • Lay all faces side by side in vector form to form a matrix – In my example: 300 faces. So the matrix is 10000 x 300 • Multiply the matrix by its transpose – The correlation matrix is 10000x10000 17 Sep 2013 11-755/18-797 47

  20. Eigen faces [U,S] = eig(correlation)    . 0 . 0   eigenface1 eigenface2 1      0 0 . 0    2   U  S     . . . . .       . . . . .         0 . 0 .  10000 • Compute the eigen vectors – Only 300 of the 10000 eigen values are non-zero • Why? • Retain eigen vectors with high eigen values (>0) – Could use a higher threshold 17 Sep 2013 11-755/18-797 48

  21. Eigen Faces eigenface1 eigenface2   eigenface1 eigenface2      U         eigenface3 • The eigen vector with the highest eigen value is the first typical face • The vector with the second highest eigen value is the second typical face. • Etc. 17 Sep 2013 11-755/18-797 49

  22. Representing a face w 1 + w 2 + w 3 =         Representation = [ w 1 w 2 w 3 …. ] T       • The weights with which the eigen faces must be combined to compose the face are used to represent the face! 17 Sep 2013 11-755/18-797 50

  23. Energy Compaction Example • One outcome of the “energy compaction principle”: the approximations are recognizable • Approximating a face with one basis: f  w 1 v 1 17 Sep 2013 11-755/18-797 51

  24. Energy Compaction Example • One outcome of the “energy compaction principle”: the approximations are recognizable • Approximating a face with one Eigenface: f  w 1 v 1 17 Sep 2013 11-755/18-797 52

  25. Energy Compaction Example • One outcome of the “energy compaction principle”: the approximations are recognizable • Approximating a face with 10 eigenfaces:    v v v f w w ... w 1 1 2 2 10 10 17 Sep 2013 11-755/18-797 53

  26. Energy Compaction Example • One outcome of the “energy compaction principle”: the approximations are recognizable • Approximating a face with 30 eigenfaces:       f w v w v ... w v ... w v 1 1 2 2 10 10 30 30 17 Sep 2013 11-755/18-797 54

  27. Energy Compaction Example • One outcome of the “energy compaction principle”: the approximations are recognizable • Approximating a face with 60 eigenfaces:         f w v w v ... w v ... w v ... w v 1 1 2 2 10 10 30 30 60 60 17 Sep 2013 11-755/18-797 55

  28. How did I do this? • Hint: only changing weights assigned to Eigen faces.. 17 Sep 2013 11-755/18-797 56

  29. Class specificity eigenface2 eigenface1 eigenface3 • The Eigenimages (bases) are very specific to the class of data they are trained on – Faces here • They will not be useful for other classes 17 Sep 2013 11-755/18-797 57

  30. Class specificity • Eigen bases are class specific • Composing a fishbowl from Eigenfaces 17 Sep 2013 11-755/18-797 58

  31. Class specificity • Eigen bases are class specific • Composing a fishbowl from Eigenfaces • With 1 basis f  1 v w 1 17 Sep 2013 11-755/18-797 59

  32. Class specificity • Eigen bases are class specific • Composing a fishbowl from Eigenfaces • With 10 bases     f w v w v ... w v 1 1 2 2 10 10 17 Sep 2013 11-755/18-797 60

  33. Class specificity • Eigen bases are class specific • Composing a fishbowl from Eigenfaces • With 30 bases       f w v w v ... w v ... w v 1 1 2 2 10 10 30 30 17 Sep 2013 11-755/18-797 61

  34. Class specificity • Eigen bases are class specific • Composing a fishbowl from Eigenfaces • With 100 bases         f w v w v ... w v ... w v ... w v 1 1 2 2 10 10 30 30 100 100 17 Sep 2013 11-755/18-797 62

  35. Universal bases • Universal bases.. • End up looking a lot like discrete cosine transforms!!!! • DCTs are the best “universal” bases – If you don’t know what your data are, use the DCT 17 Sep 2013 11-755/18-797 63

  36. SVD instead of Eigen   eigenface1 eigenface2    10000x300   U S=300x300 V=300x300   = M = Data Matrix U=10000x300       • Do we need to compute a 10000 x 10000 correlation matrix and then perform Eigen analysis? – Will take a very long time on your laptop • SVD – Only need to perform “Thin” SVD. Very fast • U = 10000 x 300 – The columns of U are the eigen faces! – The Us corresponding to the “zero” eigen values are not computed • S = 300 x 300 • V = 300 x 300 17 Sep 2013 11-755/18-797 64

  37. Using SVD to compute Eigenbases [U, S, V] = SVD(X) • U will have the Eigenvectors • Thin SVD for 100 bases: [U,S,V] = svds(X, 100) • Much more efficient 17 Sep 2013 11-755/18-797 65

  38. Eigenvectors and scatter Pixel 2 Pixel 1 • Turns out: Eigenvectors represent the major and minor axes of an ellipse centered at the origin which encloses the data most compactly • The SVD of data matrix X uncovers these vectors 17 Sep 2013 11-755/18-797 66

  39. What about sound? • Finding Eigen bases for speech signals: • Look like DFT/DCT • Or wavelets • DFTs are pretty good most of the time 17 Sep 2013 11-755/18-797 67

  40. Eigen Analysis • Can often find surprising features in your data • Trends, relationships, more • Commonly used in recommender systems • An interesting example.. 17 Sep 2013 11-755/18-797 68

  41. Eigen Analysis • Cheng Liu’s research on pipes.. • SVD automatically separates useful and uninformative features 17 Sep 2013 11-755/18-797 69

  42. Eigen Analysis • But for all of this, we need to “preprocess” data • Eliminate unnecessary aspects – E.g. noise, other externally caused variations.. 17 Sep 2013 11-755/18-797 70

  43. NORMALIZING OUT VARIATIONS 17 Sep 2013 11-755/18-797 71

  44. Images: Accounting for variations • What are the obvious differences in the above images • How can we capture these differences – Hint – image histograms.. 17 Sep 2013 11-755/18-797 72

  45. Images -- Variations • Pixel histograms: what are the differences 17 Sep 2013 11-755/18-797 73

  46. Normalizing Image Characteristics • Normalize the pictures – Eliminate lighting/contrast variations – All pictures must have “similar” lighting • How? • Lighting and contrast are represented in the image histograms: 17 Sep 2013 11-755/18-797 74

  47. Histogram Equalization • Normalize histograms of images – Maximize the contrast • Contrast is defined as the “flatness” of the histogram • For maximal contrast, every greyscale must happen as frequently as every other greyscale 0 255 • Maximizing the contrast: Flattening the histogram – Doing it for every image ensures that every image has the same constrast • I.e. exactly the same histogram of pixel values – Which should be flat 17 Sep 2013 11-755/18-797 75

  48. Histogram Equalization • Modify pixel values such that histogram becomes “flat”. • For each pixel – New pixel value = f(old pixel value) – What is f()? • Easy way to compute this function: map cumulative counts 17 Sep 2013 11-755/18-797 76

  49. Cumulative Count Function • The histogram (count) of a pixel value X is the number of pixels in the image that have value X – E.g. in the above image, the count of pixel value 180 is about 110 • The cumulative count at pixel value X is the total number of pixels that have values in the range 0 <= x <= X – CCF(X) = H(1) + H(2) + .. H(X) 17 Sep 2013 11-755/18-797 77

  50. Cumulative Count Function • The cumulative count function of a uniform histogram is a line • We must modify the pixel values of the image so that its cumulative count is a line 17 Sep 2013 11-755/18-797 78

  51. Mapping CCFs Move x axis levels around until the plot to the left looks like the plot to the right • CCF(f(x)) -> a*f(x) [or a*(f(x)+1) if pixels can take value 0] – x = pixel value – f() is the function that converts the old pixel value to a new (normalized) pixel value – a = (total no. of pixels in image) / (total no. of pixel levels) • The no. of pixel levels is 256 in our examples • Total no. of pixels is 10000 in a 100x100 image 17 Sep 2013 11-755/18-797 79

  52. Mapping CCFs • For each pixel value x: – Find the location on the red line that has the closet Y value to the observed CCF at x 17 Sep 2013 11-755/18-797 80

  53. Mapping CCFs f(x1) = x2 f(x3) = x4 Etc. x3 x1 x4 x2 • For each pixel value x: – Find the location on the red line that has the closet Y value to the observed CCF at x 17 Sep 2013 11-755/18-797 81

  54. Mapping CCFs Move x axis levels around until the plot to the left looks like the plot to the right • For each pixel in the image to the left – The pixel has a value x – Find the CCF at that pixel value CCF(x) – Find x’ such that CCF(x’) in the function to the right equals CCF(x) • x’ such that CCF_flat(x’) = CCF(x) – Modify the pixel value to x’ 17 Sep 2013 11-755/18-797 82

  55. Doing it Formulaically    ( ) CCF x CCF    min f ( x ) round Max . pixel . value      Npixels CCF min • CCF min is the smallest non-zero value of CCF(x) – The value of the CCF at the smallest observed pixel value • Npixels is the total no. of pixels in the image – 10000 for a 100x100 image • Max.pixel.value is the highest pixel value – 255 for 8-bit pixel representations 17 Sep 2013 11-755/18-797 83

  56. Or even simpler • Matlab: – Newimage = histeq(oldimage) 17 Sep 2013 11-755/18-797 84

  57. Histogram Equalization • Left column: Original image • Right column: Equalized image • All images now have similar contrast levels 17 Sep 2013 11-755/18-797 85

  58. Eigenfaces after Equalization • Left panel : Without HEQ • Right panel: With HEQ – Eigen faces are more face like.. • Need not always be the case 17 Sep 2013 11-755/18-797 86

  59. Detecting Faces in Images 17 Sep 2013 11-755/18-797 87

  60. Detecting Faces in Images • Finding face like patterns – How do we find if a picture has faces in it – Where are the faces? • A simple solution: – Define a “typical face” – Find the “typical face” in the image 17 Sep 2013 11-755/18-797 88

  61. Finding faces in an image • Picture is larger than the “typical face” – E.g. typical face is 100x100, picture is 600x800 • First convert to greyscale – R + G + B – Not very useful to work in color 17 Sep 2013 11-755/18-797 89

  62. Finding faces in an image • Goal .. To find out if and where images that look like the “typical” face occur in the picture 17 Sep 2013 11-755/18-797 90

  63. Finding faces in an image • Try to “match” the typical face to each location in the picture 17 Sep 2013 11-755/18-797 91

  64. Finding faces in an image • Try to “match” the typical face to each location in the picture 17 Sep 2013 11-755/18-797 92

  65. Finding faces in an image • Try to “match” the typical face to each location in the picture 17 Sep 2013 11-755/18-797 93

  66. Finding faces in an image • Try to “match” the typical face to each location in the picture 17 Sep 2013 11-755/18-797 94

  67. Finding faces in an image • Try to “match” the typical face to each location in the picture 17 Sep 2013 11-755/18-797 95

  68. Finding faces in an image • Try to “match” the typical face to each location in the picture 17 Sep 2013 11-755/18-797 96

  69. Finding faces in an image • Try to “match” the typical face to each location in the picture 17 Sep 2013 11-755/18-797 97

  70. Finding faces in an image • Try to “match” the typical face to each location in the picture 17 Sep 2013 11-755/18-797 98

  71. Finding faces in an image • Try to “match” the typical face to each location in the picture 17 Sep 2013 11-755/18-797 99

  72. Finding faces in an image • Try to “match” the typical face to each location in the picture • The “typical face” will explain some spots on the image much better than others – These are the spots at which we probably have a face! 17 Sep 2013 11-755/18-797 100

Recommend


More recommend