|
|
||
|---|---|---|
| .. | ||
| images | ||
| lab | ||
| Dropout.ipynb | ||
| README.md | ||
| TrainingTricks.md | ||
| TransferLearningPyTorch.ipynb | ||
| TransferLearningTF.ipynb | ||
| pytorchcv.py | ||
| tfcv.py | ||
README.md
Pre-trained Networks and Transfer Learning
Training CNNs can take a lot of time, and a lot of data is required for that task. However, much of the time is spent to learn the best low-level filters that a network is using to extract patterns from images. A natural question arises - can we use a neural network trained on one dataset and adapt it to classifying different images without full training process?
Pre-lecture quiz
This approach is called transfer learning, because we transfer some knowledge from one neural network model to another. In transfer learning, we typically start with a pre-trained model, which has been trained on some large image dataset, such as ImageNet. Those models can already do a good job extracting different features from generic images, and in many cases just building a classifier on top of those extracted features can yield a good result.
Pre-Trained Models as Feature Extractors
Convolutional networks that we have talked about in previous section contained a number of layers, each of which is supposed to extract some features from the image, starting from low-level pixel combinations (such as horizontal/vertical line or stroke), up to higher level combinations of features, corresponding to things like an eye of a flame. If we train CNN on sufficiently large dataset of generic and diverse images, the network should learn to extract those common features.
Both Keras and PyTorch contain functions to easily load pre-trained neural network weights for some common architectures, most of which were trained on ImageNet images. The most often used ones are described in CNN Architectures page. In particular, you may want to consider using one of the following:
- VGG-16/VGG-19 are relatively simple models, but they give good accuracy. Often using VGG as a first attempt is a good choice to see how transfer learning is working.
- ResNet is a family of models proposed by Microsoft Research in 2015. They have more layers, and thus take more resources.
- MobileNet is a family of models with reduced size, suitable for mobile devices. Use them if you are short in resources, and can sacrifice a little bit of accuracy.
Here are sample features extracted from a picture of a cat by VGG-16 network:
Cats vs. Dogs Dataset
In this example, we will use a dataset of Cats and Dogs, which is very close to a real-life image classification scenario.
Continue in Notebook
Let's see transfer learning in action in corresponding notebooks:
Post-lecture quiz
Lab
In this lab, we will use real-life Oxford-IIIT pets dataset with 35 breeds of cats and dogs, and we will build a transfer learning classifier.
✅ Todo: there is an unlinked file: TrainingTricks.md
