Transfer learning is the reuse of a pre-trained model on a new problem. It’s currently very popular in deep learning because it can train deep neural networks with comparatively little data. This is very useful since most real-world problems typically do not have millions of labelled data points to train such complex models.
In transfer learning, the knowledge of an already trained machine learning model is applied to a different but related problem. With transfer learning, we basically try to exploit what has been learned in one task to improve generalization in another. We transfer the weights that a network has learned at “task A” to a new “task B.”
Transfer learning is mostly used in computer vision and natural language processing tasks like sentiment analysis due to the huge amount of computational power required.
VGG16 is a convolutional neural network model proposed by K. Simonyan and A. Zisserman from the University of Oxford in the paper “Very Deep Convolutional Networks for Large-Scale Image Recognition”. The model achieves 92.7% top-5 test accuracy in ImageNet, which is a dataset of over 14 million images belonging to 1000 classes. It was one of the famous model submitted to ILSVRC-2014. It makes the improvement over AlexNet by replacing large kernel-sized filters (11 and 5 in the first and second convolutional layer, respectively) with multiple 3×3 kernel-sized filters one after another. VGG16 was trained for weeks and was using NVIDIA Titan Black GPU’s.
Here’s what we are going to do…
- Make a dataset of two classes (two persons) each having 1000 face images using OpenCV library through WebCam
- Load the VGG16 model using Keras and freeze all layers except the top 4
- Make a function that returns our Fully Connected Head
- Get all model layers
- Add our FC Head back onto VGG16 and get summary
- Load our face samples Dataset. Point to noted here is that we split our dataset in two parts — Training & Testing. For training we give only 80% of data (800 face images) and remaining 20% (200 face images) for testing/validation
- Train top layers and save model
- Load saved model as a classifier
- Finally Predict — Face Recognition by testing classifier on some test images.
Problem Statement: Create a project using transfer learning solving various problems like Face Recognition and Image Classification, using existing Deep Learning models like VGG16, etc.
Step 1: Collect the dataset
For creating any model, the fundamental requirement is a dataset. So let’s collect some data.
Import Keras, VGG16 function and then freeze layers.
Create a function in which we will define new layers to be added to the existing model.
Define the path where the training and testing data is present.
Use PMSprop as the optimizer.
Now test the model.