Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify scikit-learn's eigenface face recognition example

Tags:

I am trying to adapt scikit-learn's eigenface face recognition script to be used on my own image dataset (of note, this script runs perfectly on my Python 3, sklearn 0.17).

The below call to fetch_lfw_people() is what probably needs modification and I have struggled trying to have the script skip this to instead point to my own image folders.

I'd like the script -- instead of pulling data from the folders it downloads -- to get images from my own dataset located at '/User/pepe/images/'.

# Download the data, if not already on disk and load it as numpy arrays

lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4)

# introspect the images arrays to find the shapes (for plotting)
n_samples, h, w = lfw_people.images.shape

# for machine learning we use the 2 data directly (as relative pixel
# positions info is ignored by this model)
X = lfw_people.data
n_features = X.shape[1]

# the label to predict is the id of the person
y = lfw_people.target
target_names = lfw_people.target_names
n_classes = target_names.shape[0]

etc...

Do you have any suggestions on how to tackle this?

As you can see from the GitHub code, the central piece is actually not fetch_lfw_people() itself, but the lfw.py file that has additional functions.

like image 649
pepe Avatar asked May 03 '16 16:05

pepe


1 Answers

You don't need to 'modify' anything, the function provides an easy way for this.

See:

https://github.com/scikit-learn/scikit-learn/blob/14031f6/sklearn/datasets/lfw.py#L229

The parameters data_home (give your path here!) and download_if_missing (unset it ie. provide False value for it) are there exactly for this purpose!

like image 139
0xc0de Avatar answered Sep 28 '22 02:09

0xc0de