Whenever I hear the words “transfer learning”, it reminds me of above picture where a big brother lends his hand to pull me up. Transfer learning exemplifies this behavior by learning from one task and allowing it to be used for other task with little bit of fine tuning.
Traditional Machine learning, we always start from scratch. We gather big training dataset, use typical deep learning algo and train all the layers of the model. If you have another use case, you start from scratch again. So each model is trained in isolation with no reuse of any kind. This is resource and cost intensive. The size of dataset on each use case is huge and is nit trivial to create. In transfer learning scenario, we reuse model which was once on huge dataset like Imagenet only once by experts using Convolutional Neural Network. There are several predefined network architecture which are already available
VGGNET : 1st runner up in imagenet 2014 imagenetRESNET: Winner in Imagenet 2015Inception: Google. Winner of ILSVRC14
All of these model uses CNN behind the scenes. We then reuse these model, freeze all layers except top one, cut the top layer, add our own fully connected layer and train it using smaller image dataset under consideration. This requires a lot less data, training is much faster and accuracy is also much higher.
The reason leveraging existing network is possible becaus of the CNN learn features. At its lowest level, CNN layers learn to detect edges, at next layer it learns to detect parts of object and at last layers it learns to detect entire object. When you change training dataset, lower layers needs not changes because they need to do sam of edge detection and parts of image detection. Only top layers that does final classification need to change.
There are 2 types of transfer learning
Freezing: Here we remove top layers, freeze the weights of all remaining layers, add new fully connected laters and retraining it smaller st of images. We use this technique when data similarity is high and data size is small.
2. Fine Tuning: Here we freeze few layers and then fine tune remaining layers using another dataset. We use this technique when data similarity is low and data size is small.
We are going to use VGG 16 model and fine tune it for classifying simpsons characters.
Here is our goal, given a image of Simspon character, we would like to predict its name.
The training data that we use in this case is Simpsons Character Data. The folder consists of sub folder for each character and each subfolder consists of images. Lets read training data into pandas dataframe.
We need to convert labels into one hot encoded vectors as follows
Lets prepare training data by loading images from pandas dataframe. We will also split data into training, validation and test data
We then load VGG 16 model V3, chop off its head, fine tune lower layers and add new fully connected layers
Now the model is trained , we can observed its performance. As you can see validation loss and accuracy have improved over time.
We can now test model on test data
The output breed for specified images can now be displayed right on top of the image
Thus we saw that how quickly we were able adapt VGG 16 model to learn to classify dog breed data.
If you would like to l how to use VGG 16 model V3 using step by step video with complete code, please sign up for my course at
About Author Evergreen Technologies:
Active in teaching online courses in Computer vision , Natural Language Processing and SaaS system developmentOver 20 years of experience in fortune 500 companiesBlog: https://www.evergreentech.onlineYoutube Channel: https://www.youtube.com/channel/UCPyeQQp4CfprsybVr8rgBlQ?view_as=subscriber
•Linked in: @evergreenllc2020
Over 22,000 students in 145 countries