Face Recognition using Transfer Learning
Transfer Learning (TL) is an approach used in Machine Learning which involves adding more categories or experiences to the older one. Basically, the older weights in the model are transferred and some new weights are added to the model, thus, enriching its efficiency and accuracy.
TL can be used to solve various use-cases such as face recognition which could distinguish between faces of different classes. This article discusses how a face recognition system can be build using the strength of TL.
Dataset :
A dataset having images of 3 classes (of celebrities) has been used for the purpose of training the model. It consists of around 80 images per celebrity for training and around 20 images per celebrity for validation.
Architecture :
From various advanced CNN architectures, VGG-16 has been used in the project. It consists of 13 Covolution-ReLU-Pooling (CRP) layers and 3 Fully Connected (FC) layers. It has been used as a pre-trained model. Also, the model weights of ImageNet have been used which is known to have a collection of over 14 million images.
In order to transfer the weights of ImageNet, the layers in the VGG-16 model have been "freezed" so that the weights are not altered after every training cycle of the model.
Discussing about the layers in Neural Network (NN), it consists of 4 hidden layers having different number of neurons with 'ReLU' as activation function and an output layer with 'Softmax' as activation function which will distinguish between the 3 input classes fed to the model and gives the output.
The summary of model indicates that there are about 2.2 million trainable parameters or weights in the model.
Since, a model which works on images needs a huge amount of data as input, so the concept of Image Augmentation can be used to increase the dataset. Basically, Image Augmentation makes some changes in the properties of already existing dataset by applying operations like resize, rotate, flip etc and generate new data. This is illustrated by the ImageDataGenerator() function (offered by Keras library of Python) in the image below.
Training :
For training the model, all the layers in NN are compiled together and the data is fitted in the model. During fitting, the number of epochs are defined (here, 5) which help in adjusting the weights to minimize the error. Also, the metrics have been enabled so that the accuracy of model is visible after every epoch.
With every epoch, if the error of model reduces from the previous value, the model is saved in 'celeb_vgg.h5' file.
After training, the validation accuracy of model came out to be 69.66% in just 5 epochs.
Testing :
For testing, the model is first loaded into the 'classifier' variable. Then, 10 random images are picked from the 'validation' folder and tested against the model.
The output of the program is displayed below :
So, a use-case of Transfer Learning has been illustrated in the form of a Face Recognition system.
Conclusion :
Transfer Learning has better accuracy than the traditional ML approach and also, improves the performance of the model. Thus, it has a huge scope in future that may be able to solve and simplify complex problems.