IKH

Transfer Learning in Python

In this segment, you will learn to implement transfer learning in Python. For this implementation, we will use the Flower recognition dataset from Kaggle. This dataset has around 4000 images from 5 different classes, namely daisy, dandelion, rose, sunflower and tulip.

Running the Notebook on Nimblebox GPU

We recommend that you use a GPU to run the transfer learning notebook (provided below). For running this notebook, you would require to create your Kaggle account and download the dataset from Kaggle directly. It takes approximately 20 minutes to run the code on GPU. The instructions to start the Nimble box machine and download the dataset are present below.

Note: For running the notebooks for GNN, start the GNN Assignment machine and not RNN Assignments as mentioned in the instructions. The notebook for this tutorial is already present in the ‘GNN Assignment’ machine.

The following lecture demonstrates the notebook.

To summarise, we conducted two transfer learning experiments. In the first experiment, we removed the last fully connected layers of ResNet (which had learnt how to classify the 1000 ImageNet images). Instead, we added our own pooling, fully connected and a 5-softmax layer and trained only those.

Notice that we got very good accuracy in just a few epochs. In case we weren’t satisfied with the results, we could modify this network further (add an FC layer, modify the learning rate, replace the global average pooling layer with max pool, etc.).

In the second experiment, we froze the first 140 layers of the model (i.e. used the pre-trained ResNet weights from layers 1-140) and trained the rest of the layers. Note that while updating the pre-trained weights, we should use a small learning rate. This is because we do not expect them to have learnt some generic patterns, and want to tune them only a little to accommodate for the new task).

In the next two segments, you will go through an interesting recent paper which compares various CNN architectures from an efficiency and deployment point of view.

Report an error