microsoft/AI-For-Beginners

Public

mirrored from https://github.com/microsoft/AI-For-BeginnersAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
6c2953e954e3bbc8d54db06124aac4fd78db2ebc

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

4-ComputerVision/08-TransferLearning/README.md

35lines · modecode

1# Pre-trained Networks and Transfer Learning
2
3Training 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?
4
5This 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.
6
7## Pre-Trained Models as Feature Extractors
8
9Convolutional 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.
10
11Both 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](../07-ConvNets/CNN_Architectures.md) page. In particular, you may want to consider using one of the following:
12
13* **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.
14* **ResNet** is a family of models proposed by Microsoft Research in 2015. They have more layers, and thus take more resources.
15* **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.
16
17Here are sample features extracted from a picture of a cat by VGG-16 network:
18
19![Features extracted by VGG-16](images/features.png)
20
21## Cats vs. Dogs Dataset
22
23In this example, we will use a dataset of [Cats and Dogs](https://www.microsoft.com/en-us/download/details.aspx?id=54765&WT.mc_id=academic-57639-dmitryso), which is very close to a real-life image classification scenario.
24
25## Continue in Notebook
26
27Let's see transfer learning in action in corresponding notebooks:
28
29* [Transfer Learning - PyTorch](TransferLearningPyTorch.ipynb)
30* [Transfer Learning - TensorFlow](TransferLearningTF.ipynb)
31
32## [Lab](lab/README.md)
33
34In this lab, we will use real-life [Oxford-IIIT](https://www.robots.ox.ac.uk/~vgg/data/pets/) pets dataset with 35 breeds of cats and dogs, and we will build a transfer learning classifier.
35