We will cover the following tasks in 34 minutes:
Introduction and Importing Libraries
This project is based on the Deep Face Recognition paper presented in the British Machine Vision Conference, 2015 by a group of researchers led by O.M.Parkhi. They used the popular VGG16 architecture and trained it on a few thousand human face images downloaded from the internet. We will get to how this model was trained in one of the tasks in this project. As a starting point, we will import the libraries and helper functions that we will need in this project.
The researchers who trained the VGG Face model used a bunch of face images to train their model and one of their objectives was to train a model which could be applicable to face verification tasks. First, trained a face classifier with their data of 2662 unique individuals. This was setup as a classification problem with 2622 classes.
Because of this classification training, the model had to learn a lot of facial feature nuances in order to be able to give high enough accuracy across 2622 individuals. And we can use a deep layer to extract these feature nuances, called face descriptor, and use that output as a somewhat smaller dimension represenation of the learned features. Then, when we try to do face verification, we can simply compare this representation of two face images and if the two representations are somewhat similar, then we can conclude that they are of the same person and if the representations are different, then the images are probably not of the same person.
We want to preprocess our images before we feed them to our face descriptor. Fortunately, Keras comes with a bunch of helper functions that we can use. We are going to use one image at a time to get inference and then use two feature descriptor comparisons. So, we will first resize the images to make them suitable for our model and then convert the images into NumPy arrays.
We are going to implement a simple function that will calculate euclidean distance between two vectors. These vectors are basically going to be our outputs from the face descriptor model given two images as inputs - one image at a time. Even though it’s obvious, but let me remind you that we are not going to train the face descriptor. We are using the pre-trained weights from the VGG Face model. So, there’s not going to be any training involved but we are simply using a vector output of a deep layer from the pre-trained model as our facial feature descriptor. So, when we get this vector for one image, that represents a bunch of complex facial features for that image. In order to verify if the two images are of the same person’s face, we will get the two face descriptor vector outputs for the two images and see if they are similar.
Finally, we have everything we need for the face verification system setup. We have the face descriptor, we have the function that gives us preprocessed images as NumPy arrays in the shape that we’d need and we have a function to calculate euclidean distance between two vectors.
Let’s put it all to use and create a function the perform face verification. We’re going to set a threshold which seems to work well during testing. But this can be changed depending on how well it performs. Consider this to be a hyperparameter that, given more validation, can be adjusted.
Finally, we use our
verify method written in the previous task to make comparisons between various photos of faces. It’s interesting to note that this method works even if the photos of a person are in different colour, has different angles or lighting and also if they were taken at different ages.
About the Host (Amit Yadav)
I am a Software Engineer with many years of experience in writing commercial software. My current areas of interest include computer vision and sequence modelling for automated signal processing using deep learning as well as developing chatbots.