20.03.2021 Views

Deep-Learning-with-PyTorch

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

168 CHAPTER 7 Telling birds from airplanes: Learning from images

0

5

10

15

20

25

30

0 5 10 15 20 25 30

Figure 7.3 The 99th image from the

CIFAR-10 dataset: an automobile

7.1.3 Dataset transforms

That’s all very nice, but we’ll likely need a way to convert the PIL image to a PyTorch

tensor before we can do anything with it. That’s where torchvision.transforms

comes in. This module defines a set of composable, function-like objects that can be

passed as an argument to a torchvision dataset such as datasets.CIFAR10(…), and

that perform transformations on the data after it is loaded but before it is returned by

__getitem__. We can see the list of available objects as follows:

# In[8]:

from torchvision import transforms

dir(transforms)

# Out[8]:

['CenterCrop',

'ColorJitter',

...

'Normalize',

'Pad',

'RandomAffine',

...

'RandomResizedCrop',

'RandomRotation',

'RandomSizedCrop',

...

'TenCrop',

'ToPILImage',

'ToTensor',

...

]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!