Implementing transfer learning with PyTorch

Now that we know what TL is, let's look at whether it works in practice. In this section, we'll apply an advanced ImageNet pretrained network on the CIFAR-10 images with PyTorch 1.3.1 and the torchvision 0.4.2 package. We'll use both types of TL. It's preferable to run this example on a GPU.

Let's get started:

  1. Do the following imports:
import torchimport torch.nn as nnimport torch.optim as optimimport torchvisionfrom torchvision import models, transforms
  1. Define batch_size for convenience:
batch_size = 50
  1. Define the training dataset. We have to consider a few things: ...

Get Advanced Deep Learning with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.