Facebook DeepFace (FAIR) can recognize faces in any pictures with an extremely high accuracy rate and precision. Thanks to the deep learning technology and sophisticated algorithm combined with a large amount of data, it is now possible to train systems to achieve near human image processing capabilities.
In this post, I will give an overview of a very simple face recognition system developed in MATLAB® following sample codes for you to try.
We want to build a perceptron to identify the following features in a face:
- Gender of the person in the picture
- Whether the person is wearing glasses and
- Whether the person is smiling
- Windows PC/ MAC OS X/ Linux with MATLAB preinstalled
- A large database of Face images, divided into two sets, train images and test images, both with an attribute file for the desired features.
- All face images need to be aligned for their eye position which we will discuss later
Perceptron. A perceptron is the basic building block of any Artificial Neural Network.
It consists of a single neuron with several inputs and often a single output. The following Wikipedia article gives a lot more details about the perceptron: https://en.wikipedia.org/wiki/Perceptron
Training Data Import (file_importer.m)
Colour Images are in the form of a 3D matrix with the image width, image height and colour depth. However, a perceptron only takes input in the form of a column vector. Also, it is important for all images to be of the same size so there is no matrix size mismatch error. So we do the following:
- Crop the images to be of the same size (101x101x3)
- Convert the images to grayscale to reduce the resolution (101×101)
- Reshape the image matrix to a column vector
- Repeat the process for test images
- Attribute files are simple text files containing the attribute values for all the 3 features.
- We simply open the file and read the contents and store this in a matrix for all the images
- Repeat the process separately for test images
- Once all the information is obtained store the workspace for future use (image_import.mat)
In this step, we want to learn the weights for our perceptron. So, we simply use the training image and attribute files information to perform the training process. We can repeat the process until there is zero error in the training set. Store the workspace for testing purposes as (face_perceptron-workspace.mat)
Converting the value of w in the form of an image shows the following:
Now we can use the weights already obtained in the training phase and run that across the test set to verify how well our system has learnt the features.
I have developed an app that does the following:
- Requests the user to select an image file (.jpg) as an input.
- it uses the trained to weights to then recognize the features of that image and displays the information using a dialog box.
Note that this will work well only if the image is well aligned with respect to the eyes.
|Feature recognized incorrectly – Image not aligned||Feature recognized correctly – Image aligned|
All the resources are available in the following Github Project:
Let me know if you have any suggestions for improvements through comments below. Of course, remember that this is a simple algorithm that uses a perceptron with no special optimization technique as that was the primary purpose of this post and not getting too sophisticated with the design.
Feel free to fork the Github project to develop your own facial attribute recognizer.