Transfer Learning

Learn to modify a pretrained classification CNN to adapt it to another classification task.

We'll cover the following...

Pretrained CNNs are available to download for free. That is great if you want to classify images happening to be part of the 1000 classes from the ImageNet dataset. Examples of categories are “Tibetan mastiff,” “analog clock,” and “sombrero.”

Press + to interact
An unlikely inspection scenario
An unlikely inspection scenario

In the context of automated inspection, it is unlikely that the object classes we care about are part of this set. A typical classification scenario would be between some components that might or might not be present on an assembled part. It could be, for example, capacitors, chips, or diodes on an electronic card. These components are absent from the classes used to train GoogLeNet or ResNet50.

That does not mean that pretrained CNNs are useless for automated inspection. We can use them to get a head start in training in place of a random weight initialization. The principle is to exploit the feature detectors embedded in the weights of the convolution layers. At least some of these features (edges, color gradients, corners, etc.) are valuable for the classification task at hand.

GoogLeNet

...
Press + to interact
import torch
import torchvision
# Load the pre-trained GoogLeNet CNN and the corresponding transform pipeline
googlenet = torchvision.models.googlenet(weights='DEFAULT', progress=False)
transform = torchvision.models.GoogLeNet_Weights.IMAGENET1K_V1.transforms(antialias=True)
print(f"googlenet:\n{googlenet}")
...