Using MobileNet to make a Celeb-Recognition Classifier with Transfer Learning
Brief about Transfer Learning: Transfer Learning is a technique in which we use a model that is pre-trained on a very large dataset, and by the weights of that model can be used in some other problem so that we can save us time and extensive computational power for some another task.
Transfer Learning Explained
Here’s how it works: First, you delete what’s known as the “loss output” layer, which is the final layer used to make predictions, and replace it with a new loss output layer for some particular prediction. This loss output layer is a fine-tuning node for determining how training penalizes deviations from the labeled data and the predicted output.
Next, you would take your smaller dataset and train it on the entire 50-layer neural network or the last few layers or just the loss layer alone. By applying these transfer learning techniques, your output on the new CNN will be identification based on your particular dataset.
Some of the famous pre-trained models present are ResNet50, VGG16, VGG19, MobileNet, inception V3, etc.
The overall architecture of the Mobilenet is as follows, having 30 layers with
- convolutional layer with stride 2
- depthwise layer
- pointwise layer that doubles the number of channels
- depthwise layer with stride 2
- pointwise layer that doubles the number of channels
etc.
First Step: First Step is to Load the MobileNet Model and Freeze all layers except the top 4, as we'll only be training the top 4.
NOTE: Here Freezing means we will not be using these layers as we don't want to train all the layers again that's the whole and sole purpose of transfer learning.
Second Step: We'll make a function that returns our FC Head and then we will add our FC Head back onto MobileNet
Third Step: Third Step is to Load our Celeb-Recognition Dataset to get the Details about the Dataset like total number of Images and Classes in both Tran and Validation.
Fourth Step: Fourth Step is to Train our model, I am using five epochs and 16 Batch Size here.
Here I am getting around 80% accuracy which is pretty good considering I've given only 150 images to train with only 5 epochs.
Final Step: Final Step is to load our classifier and test some images
Github Link for Code: https://github.com/Pulkit-debug/MLOps_Projects_Data/tree/master/MLOps_Project_4