CSE 152 : Introduction to Computer Vision, Spring 2018 Assignment 5

Similar documents
HW0 v3. October 2, CSE 252A Computer Vision I Fall Assignment 0

Search. The Nearest Neighbor Problem

CSE 547: Machine Learning for Big Data Spring Problem Set 2. Please read the homework submission policies.

HW5. March 7, CSE 252B: Computer Vision II, Winter 2018 Assignment 5

FACE RECOGNITION USING SUPPORT VECTOR MACHINES

Robust Face Recognition via Sparse Representation

Recognition: Face Recognition. Linda Shapiro EE/CSE 576

CIS 520, Machine Learning, Fall 2015: Assignment 7 Due: Mon, Nov 16, :59pm, PDF to Canvas [100 points]

Face detection and recognition. Many slides adapted from K. Grauman and D. Lowe

Robust Face Recognition via Sparse Representation Authors: John Wright, Allen Y. Yang, Arvind Ganesh, S. Shankar Sastry, and Yi Ma

Inf2B assignment 2. Natural images classification. Hiroshi Shimodaira and Pol Moreno. Submission due: 4pm, Wednesday 30 March 2016.

HW2. October 24, CSE 252A Computer Vision I Fall Assignment 2

Assignment4. November 29, Follow the directions on to install Tensorflow on your computer.

Announcements. Recognition I. Gradient Space (p,q) What is the reflectance map?

Dimension Reduction CS534

Final Project Face Detection and Recognition

Recognition of Non-symmetric Faces Using Principal Component Analysis

Applications Video Surveillance (On-line or off-line)

Mobile Face Recognization

Face Recognition using Eigenfaces SMAI Course Project

Linear Discriminant Analysis in Ottoman Alphabet Character Recognition

Facial Recognition Using Eigenfaces

Face Recognition via Sparse Representation

Lecture Linear Support Vector Machines

Linear Discriminant Analysis for 3D Face Recognition System

Lecture 4 Face Detection and Classification. Lin ZHANG, PhD School of Software Engineering Tongji University Spring 2018

HW Assignment 3 (Due by 9:00am on Mar 6)

COSC160: Detection and Classification. Jeremy Bolton, PhD Assistant Teaching Professor

Face detection and recognition. Detection Recognition Sally

GENDER CLASSIFICATION USING SUPPORT VECTOR MACHINES

Deep Learning for Computer Vision

1 CSE 252A Computer Vision I Fall 2017

Homework Assignment #3

1 Lab: Digit recognition

ECE407 Project. Implementation of the Fisher Linear Discriminant (FLD) based algorithm for Face Recognition. Arindam Bose UIC ID:

Learning to Recognize Faces in Realistic Conditions

Recognition, SVD, and PCA

ENEE633 Project Report SVM Implementation for Face Recognition

Exercise 4. AMTH/CPSC 445a/545a - Fall Semester October 30, 2017

Principal Component Analysis (PCA) is a most practicable. statistical technique. Its application plays a major role in many

Fuzzy Bidirectional Weighted Sum for Face Recognition

General Instructions. Questions

Activity recognition and energy expenditure estimation

CHAPTER 3 PRINCIPAL COMPONENT ANALYSIS AND FISHER LINEAR DISCRIMINANT ANALYSIS

Autoencoder. 1. Unsupervised Learning. By Prof. Seungchul Lee Industrial AI Lab POSTECH.

Programming Exercise 7: K-means Clustering and Principal Component Analysis

Dimensionality Reduction and Classification through PCA and LDA

K-Nearest Neighbors. Jia-Bin Huang. Virginia Tech Spring 2019 ECE-5424G / CS-5824

Image Classification pipeline. Lecture 2-1

Lecture 15: High Dimensional Data Analysis, Numpy Overview

Verification: is that a lamp? What do we mean by recognition? Recognition. Recognition

What do we mean by recognition?

Unsupervised learning in Vision

ViFaI: A trained video face indexing scheme

Laplacian Faces: A Face Recognition Tool

CHAPTER 5 GLOBAL AND LOCAL FEATURES FOR FACE RECOGNITION

Announcements. Recognition I. Optical Flow: Where do pixels move to? dy dt. I + y. I = x. di dt. dx dt. = t

Image Classification pipeline. Lecture 2-1

Data Science and Machine Learning Essentials

Image-Based Face Recognition using Global Features

Training-Free, Generic Object Detection Using Locally Adaptive Regression Kernels

Perspective Projection [2 pts]

Biometrics Technology: Image Processing & Pattern Recognition (by Dr. Dickson Tong)

ECS 189G: Intro to Computer Vision, Spring 2015 Problem Set 3

Semi-Random Subspace Method for Face Recognition

A Survey on Feature Extraction Techniques for Palmprint Identification

Facial Expression Detection Using Implemented (PCA) Algorithm

CS 170 Algorithms Fall 2014 David Wagner HW12. Due Dec. 5, 6:00pm

Object and Action Detection from a Single Example

[Gaikwad *, 5(11): November 2018] ISSN DOI /zenodo Impact Factor

Colorado School of Mines. Computer Vision. Professor William Hoff Dept of Electrical Engineering &Computer Science.

Image Processing Pipeline for Facial Expression Recognition under Variable Lighting

Exercise 2. AMTH/CPSC 445a/545a - Fall Semester September 21, 2017

CSE 252A Computer Vision Homework 3 Instructor: Ben Ochoa Due : Monday, November 21, 2016, 11:59 PM

Unsupervised Learning

2. For each of the regular expressions, give a string that will matches it:

Data Structures III: K-D

Autoencoder. By Prof. Seungchul Lee isystems Design Lab UNIST. Table of Contents

FACE RECOGNITION BASED ON GENDER USING A MODIFIED METHOD OF 2D-LINEAR DISCRIMINANT ANALYSIS

CSE152 Introduction to Computer Vision Assignment 3 (SP15) Instructor: Ben Ochoa Maximum Points : 85 Deadline : 11:59 p.m., Friday, 29-May-2015

Implementation of a Face Detection and Recognition System

Data Science and Machine Learning Essentials

Face Detection and Recognition in an Image Sequence using Eigenedginess

Local Similarity based Linear Discriminant Analysis for Face Recognition with Single Sample per Person

Aprendizagem Automática. Feature Extraction. Ludwig Krippahl

Autoencoder. 1. Unsupervised Learning. By Prof. Seungchul Lee Industrial AI Lab POSTECH.

CS 195-5: Machine Learning Problem Set 5

Data Mining - Data. Dr. Jean-Michel RICHER Dr. Jean-Michel RICHER Data Mining - Data 1 / 47

Class-Information-Incorporated Principal Component Analysis

Data Mining Final Project Francisco R. Ortega Professor: Dr. Tao Li

Lab Four. COMP Advanced Artificial Intelligence Xiaowei Huang Cameron Hargreaves. October 22nd 2018

Face Recognition using FSS-DSOP for Small Sample Size Problem with Illumination

Python With Data Science

Nearest neighbors classifiers

Certified Data Science with Python Professional VS-1442

15-110: Principles of Computing, Spring 2018

UNIVERSITY OF OSLO. Faculty of Mathematics and Natural Sciences

Recognizing Handwritten Digits Using the LLE Algorithm with Back Propagation

Index. Symbols. Index 353

Extended Isomap for Pattern Classification

Transcription:

CSE 152 : Introduction to Computer Vision, Spring 2018 Assignment 5 Instructor: Ben Ochoa Assignment Published On: Wednesday, May 23, 2018 Due On: Saturday, June 9, 2018, 11:59 PM Instructions Review the academic integrity and collaboration policies on the course website. This assignment must be completed individually. This assignment contains only programming problems. All solutions must be written in this notebook Programming aspects of this assignment must be completed using Python in this notebook. If you want to modify the skeleton code, you can do so. This has been provided just to provide you with a framework for the solution. You may use python packages for basic linear algebra (you can use numpy or scipy for basic operations), but you may not use packages that directly solve the problem. If you are unsure about using a specific package or function, then ask the instructor and teaching assistants for clarification. You must submit this notebook exported as a pdf. All answers and results must be present in the.pdf file. Points will not be given for answers and results only present in the.ipynb file. You must submit both files (.pdf and.ipynb) on Gradescope. You must mark each problem on Gradescope in the pdf. It is highly recommended that you begin working on this assignment early. Introduction In this assignment, we will have a look at some simple techniques for object recognition, in particular, we will try to recognize faces. The face data that we will use is derived from the Yale Face Database. The database consists of 5760 images of 10 individuals, each under 9 poses and 64 different lighting conditions. The availability of such standardized databases is important for scientific research as they are useful for benchmarking different algorithms. http://localhost:8888/notebooks/cse152hw05.ipynb 1/7

Figure1: The Yale face database B. In this assignment, we will only use 640 images corresponding to a frontal orientation of the face. These faces are included in the file yalebfaces.zip. You will find the faces divided into five different subsets. Subset 0 consists of images where the light source direction is almost frontal, so that almost all of the face is brightly illuminated. From subset 1 to 4, the light source is progressively moved toward the horizon, so that the effects of shadows increase and not all pixels are illuminated. The faces in subset 0 will be used as training images, and subsets 1 to 4 will be used as test images. Environment Setup util.py requires cv2 library. Please run "conda install opencv" in Powershell if your are in Windows or Terminal if you are in Mac/Linux. import os, sys import numpy as np from imageio import imread import matplotlib.pyplot as plt from scipy.ndimage.filters import convolve from scipy.ndimage.filters import gaussian_filter import cv2 http://localhost:8888/notebooks/cse152hw05.ipynb 2/7

def load_subset(subsets, base_path='data/yalebfaces'): # INPUT: # subsets: the index of the subset to load, or a vector of sebset # indices. For example, loadsubset([2]) loads subset2, whereas # loadsubset([0,1]) loads subset0 and subset1 # base_path: the path to the yale dataset directory. If left blan # defaults to 'yalebfaces' # # OUTPUT: # imgs: a NXd matrix of images, where N is the number of images and # the number of pixels in each image # labels: a vector of length N, storing the person or class ID of e # image imgs = [] labels = [] for subset in subsets: directory = os.path.join(base_path, "subset" + str(subset)) files = os.listdir(directory) for img in files: face = cv2.imread(os.path.join(directory,img), cv2.imread_gra imgs.append(face) labels.append(int(img.split('person')[1].split('_')[0])) return imgs, labels def draw_faces(img_list, col=10): # Draw faces fig = plt.figure(figsize = (30,30)) if len(img_list) < col: col = len(img_list) row = 1 else: row = int(len(img_list)/col) for sub_img in range(1,row*col+1): ax = fig.add_subplot(row, col, sub_img) ax.imshow(img_list[sub_img-1], cmap='gray') ax.axis('off') plt.show() Problem 1 (Programing): Naive Recognition (15 points) For this first problem, you will do face recognition by comparing the raw pixel values of the images. Let subset 0 be the train set, and report classification accuracy on test sets 1 to 4. Use the nearest neighbor classifier (1-NN) using the l2 norm (i.e. Euclidean distance). 1. (5 points) Once you have classified all images in a test set, report the average accuracy for each test set (percentage of correctly labeled images), i.e. 4 numbers. 2. (5 points) Comment on the performance, does it make sense? Is there any difference between the sets? 3. (5 points) Show any two misclassified examples and explain why these might have been misclassified. http://localhost:8888/notebooks/cse152hw05.ipynb 3/7

def predict_naive(test_imgs, train_img, label0): # test_imgs: list of Nxd array for Subset 1-4 as test cases # train_img: Nxd array for Subset0 as trainning set # label0: training set label # Your Code Here return label1, label2, label3, label4 train_img, label0 = load_subset([0]) # Your Implememnation: You have to load the test set (Subset 1-4) by your label1, label2,label3, label4 = predict_naive(test_imgs, train_img, labe def evaluate(label1, label2, label3, label4): _, l = np.array(load_subset([1])) print("subset 1 accuracy: " + str(np.count_nonzero((np.array(label1) _, l = np.array(load_subset([2])) print("subset 2 accuracy: " + str(np.count_nonzero((np.array(label2) _, l = np.array(load_subset([3])) print("subset 3 accuracy: " + str(np.count_nonzero((np.array(label3) _, l = np.array(load_subset([4])) print("subset 4 accuracy: " + str(np.count_nonzero((np.array(label4) evaluate(label1, label2,label3, label4) def show_mislabeled_img(imgs, labels): #Your Implementation here show_mislabeled_img(imgs, labels) Problem 2 (Programing): k-nearest Neighbors Recognition (10 points) Instead of using a single nearest neighbor, sometimes it is useful to consider the consensus (majority vote) of k-nearest neighbours. Repeat Part 1.1 using k-nearest neighbor classifier (k- NN). 1. (4 points) Test the performance for each test dataset using k 1, 3, 5. Note that you already have the results for k = 1 from Part 1. 2. (4 points) Test the performance for each test dataset using the l1 norm rather than the l2 norm with k 1, 3, 5. 3. (2 points) Compare the performance of the classification with increasing k. Also comment on whether changing the distance metric influenced the results (if they did). Briefly justify the results observed. def predict_knn_l2(test_imgs, train_img, label0, k): # Your Implemenation Here return label1, label2, label3, label4 http://localhost:8888/notebooks/cse152hw05.ipynb 4/7

def predict_knn_l1(test_imgs, train_img, label0, k): # Your Implemenation Here return label1, label2, label3, label4 k = 3 train_img, label0 = load_subset([0]) # Your Implememnation: You have to load the test set (Subset 1-4) by your def evaluate(label1, label2, label3, label4): _, l = np.array(load_subset([1])) print("subset 1 accuracy: " + str(np.count_nonzero((np.array(label1) _, l = np.array(load_subset([2])) print("subset 2 accuracy: " + str(np.count_nonzero((np.array(label2) _, l = np.array(load_subset([3])) print("subset 3 accuracy: " + str(np.count_nonzero((np.array(label3) _, l = np.array(load_subset([4])) print("subset 4 accuracy: " + str(np.count_nonzero((np.array(label4) print("k = " + str(k)) print("by using l2 norm: ") label1, label2,label3, label4 = predict_knn_l2(test_imgs, train_img, lab evaluate(label1, label2,label3, label4) print("by using l1 norm: ") label1, label2,label3, label4 = predict_knn_l1(test_imgs, train_img, lab evaluate(label1, label2,label3, label4) Problem 3 (Programing): Recognition Using Eigenfaces (25 points) (5 points) Write a function eigentrain(trainset,k) that takes as input a N d matrix trainset of vectorized images from subset 0, where N = 70 is the number of training images and d = 2500 is the number of pixels in each training image. Perform PCA on the data and compute the top k = 20 eigenvectors. Return the k d matrix of eigenvectors W, and a d dimensional vector mu encoding the mean of the training images. (2 points) Rearrange each of the top 20 eigenvectors you obtained in the previous step into a 2D image of size 50 50. Display these images by appending them together into a 500 100 image (a 10 2 grid of images). (2 points) Explain the objective of performing PCA on the training images. What does this achieve? (2 points) Select one image per person from subset 0 (e.g., the 5 images person01 01.png, person02 01.png,..., person10 01.png). Show what each of these images would look like when using only the top k eigenvectors to reconstruct them, for k = 1, 2, 3, 4, 5,...10. This reconstruction procedure should project each image into a k dimensional space, project that k dimensional space back into a 2500 dimensional space, and finally resize that 2500 vector into a 50 50 image. (10 points) Write a function called eigentest(trainset,trainlabels,testset,w,mu,k) that takes as input : The same N d matrix trainset of vectorized images from subset 0 An N dimensional vector trainlabels that encodes the class label of each training image (e.g., 1 for person01, 2 for person02, etc.) http://localhost:8888/notebooks/cse152hw05.ipynb 5/7

An M d matrix testset of M vectorized images from one of the test subsets (1-4) The output of PCA i.e. W and mu, and the number of eigenvectors to use k Project each image from trainset and testset onto the space spanned by the first k eigenvectors. For each test image, find the nearest neighbor (1-NN) in the training set using an L2 distance in this lower dimensional space and predict the class label as the class of the nearest training image. Your function should return an M dimensional vector testlabels encoding the predicted class label for each test example. Evaluate eigentest on each test subset 1-4 separately for values k = 1...20 (so it should be evaluated 4 20 times). Plot the error rate (fraction of incorrect predicted class labels) of each subset as a function of k in the same plot, and use the Python legend function add a legend to your plot. (2 points) Repeat the experiment from the previous step, but throw out the first 4 eigenvectors. That is, use k eigenvectors starting with the 5th eigenvector. Produce a plot similar to the one in the previous step. How do you explain the difference in recognition performance from the previous part? (2 points) Explain any trends you observe in the variation of error rates as you move from subsets 1 to 4 and as you increase the number of eigenvectors. Use images from each subset to reinforce your claims. imgs, labels = load_subset([0]) trainset = np.reshape(imgs,(70, 2500)) def eigentrain(trainset,k): # Your Implementation Here return eigvecs, mu def displayimages(k): # Display the 500 x 100 Image # Your Implementation Here def eigentest(trainset,trainlabels,testset,w,mu,k): # Your Implementation Here # trainset: # N d matrix trainset of vectorized images from subset 0 # trainlabels: # An N dimensional vector trainlabels that encodes the class # label of each training image # testset: # M d matrix testset of M vectorized images from one of # the test subsets (1-4) # W: # Coefficients of PCA # mu: # Estimated mean # k: # number of eigenvectors Problem 4 (Programing): Recognition Using Fisherfaces http://localhost:8888/notebooks/cse152hw05.ipynb 6/7

(20 points) (10 points) Write a function called fishertrain(trainset,trainlabels,c) that takes as input the same N d matrix trainset of vectorized images from subset 0, the corresponding class labels trainlabels, and the number of classes c = 10. Your function should do the following : Compute the mean mu of the training data, and use PCA to compute the first N c principal components. Let this be W PCA. Use W PCA to project the training data into a space of dimension (N c). Compute the between-class scatter matrix S B and the within class scatter matrix S W on the (N c) dimensional space from the previous space. Compute W FLD, by solving for the generalized eigenvectors of the (c 1) largest generalized eigenvalues for the problem S B w i = λ i S W w i. You can use inbuilt functions to solve for the generalized eigenvalues of S B and S W. The fisher bases will be a W = W FLD W PCA, where W is (c 1) d dimensional, W FLD is (c 1) (N c) dimensional, and W PCA is (N c) d dimensional. (5 points) As in the Eigenfaces exercise, rearrange the top 9 Fisher bases you obtained in the previous part into images of size 50 50 and stack them into one big 450 50 image. (5 points) As in the eigenfaces exercise, perform recognition on the testset with Fisherfaces. As before, use a nearest neighbor classifier (1-NN), and evaluate results separately for each test subset 1-4 for values k = 1...9. Plot the error rate of each subset as a function of k in the same plot, and use the legend function in Python to add a legend to your plot. Explain any trends you observe in the variation of error rates with different subsets and different values of k, and compare performance to the Eigenface method. paper-link def fishertrain(trainset, trainlabel, c): #Your Implementation Here http://localhost:8888/notebooks/cse152hw05.ipynb 7/7