Skip to Content
Python Deep Learning - Second Edition
book

Python Deep Learning - Second Edition

by Ivan Vasilev, Daniel Slater, Gianmario Spacagna, Peter Roelants, Valentino Zocca
January 2019
Intermediate to advanced
386 pages
11h 13m
English
Packt Publishing
Content preview from Python Deep Learning - Second Edition

Transfer learning example with PyTorch

Now that we know what transfer learning is, let's see whether it works in practice. In this section, we'll apply an advanced ImageNet pre-trained network on the CIFAR-10 images. We'll use both types of transfer learning. It's preferable to run this example on GPU:

  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:
    • The CIFAR-10 images are 32 x 32, while the ImageNet network expects 224 x 224 input. As we are using ImageNet based network, we'll upsample the 32x32 CIFAR images to 224x224.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Deep Learning

Python Deep Learning

Valentino Zocca, Gianmario Spacagna, Daniel Slater, Peter Roelants

Publisher Resources

ISBN: 9781789348460Supplemental Content