Face Recognition using CNN(based on ResNet50 architecture) for small dataset
Building your own deep learning model(based on ResNet50) from scratch to recognize face.
So lets begin with the dataset. So we have taken face dataset of 5 famous celebrities available on Kaggle. In this data set there are 15–17 images per class. So lets store all the images to a variable but before taking input let’s discuss one more thing.
As we want to perform face recognition we will just store the images with face only. So to do this we will use a library called as MTCNN. It helps in detecting bounding box of face in a image. We will use that bounding box to crop the image and store it.
So here is the code to crop out the face.
So let use this function and store each image.
Similarly we can take input for testing dataset also. So let’s start making our model. We thought of making a deep learning model and that is based on few properties of ResNet50 model. In ResNet50 we use a skip function to retain our input image features for deeper layers. So similarly we will define a single block of 3 convolutional layers with Batch normalization in between them and apply Add function on input layer for the block and output layer of the current block. With increasing filters in each block. We will add 10 such blocks to with filters starting from 64 to 4096. Though you can change the number of filters to reduce computation but there might be chances of decrease in accuracy. So here is the code of making each block.
Let’s build the full model and compile it. We will use RMSprop as optimizer you can also use Adam. But as we were experimenting we were getting better accuracy using RMSprop optimizer.
Now as we have made our model, we can start training our model. We can train our model on our dataset directly or we can add data augmentation too. We didn’t included data augmentation as it was increasing the accuracy well. To increase dataset size we have to create more images from the available images using own made functions. So lets train the model and print the accuracy of our model on testing dataset.
You can increase the number of epochs if you choose different dataset, but with this dataset, if we increase the number of epochs model starts overfitting and accuracy starts decreasing.
We achieved an accuracy of 76 percent on testing dataset. Though there are predefined models like VGGFace2 which gave an accuracy of approx. 87 percent on the same set.
. . .
Enjoy coding!!