Skip to content

Face recognition based on eigenfaces and using a naive bayes classifier.

Notifications You must be signed in to change notification settings

devGhiles/face_recognition

Repository files navigation

Face recognition using eigenfaces and a naive bayes classifier

Dependencies

The program is written in Python 3.6.1, but it should work for any version of Python 3. See the requirements.txt file for the required libraries. If you have pip installed, you can install all the required libraries by typing the following command in the command-line:

$ pip install -r requirements.txt

Description of the files

  • image.py: contains the Image class, which is a class that wraps a 2D numpy array and creates an abstraction for an image. It has several in-place methods such as applyNoise and rotate.
  • data_reader.py: contains the class DataReader. This class reads the images from the AT&T database, wraps them using the Image class, and splits them into train, validation and test data. Also has the read method which wraps the scipy.misc.imread method for reading an image file.
  • feature_extractor.py: contains the class FeatureExtractor. This class implements the fit-transform paradigm. Given a list of images, it computes the eigenfaces and saves them for future use. It also computes the coordinates on an image in the eigenfaces basis.
  • training.py: generates the model by training a naive bayes classifier.
  • main.py: recognizes the face in a new image using the model learned by training.py.
  • noise.py: tests the robustness to noise of the system by applying different types of noises to test images (gaussian, poisson, speckle, and salt & pepper).
  • contrast_inversion.py: tests the robustness to the contrast inversion of an image.
  • rotation.py: tests the robustness to the rotation of an image.
  • translation.py: test the robustness to the shifting of an image.

Generate the model

The first step is to generate the model (which consists of training a naive bayes classifier). For that, you need to execute the file training.py:

$ python training.py

This will create two files: clf.pkl and feature_extractor.pkl.

Face recognition on a new image

The main.py file is used for that:

$ python main.py path/to/imagefile

Any image format that works with scipy.misc.imread will work (that includes '.jpg', '.png', and the more exotic '.pgm')

Test the robustness of the system

This can be done either by altering only the test data or the training data and the test data simultanously (see relevent source files for more details).

Noise:

$ python noise.py

Contrast inversion:

$ python contrast_inversion.py

Rotation:

$ python rotation.py

Translation (shifting):

$ python translation.py

References

This work was inspired by this paper.

We used the AT&T database of faces that you can find here.

About

Face recognition based on eigenfaces and using a naive bayes classifier.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages