Skip to Content
Deep Learning with PyTorch
book

Deep Learning with PyTorch

by Vishnu Subramanian
February 2018
Intermediate to advanced
262 pages
6h 59m
English
Packt Publishing
Content preview from Deep Learning with PyTorch

Loading the data

Loading data is similar to what we have seen for solving image classification problems in Chapter 5, Deep Learning for Computer Vision. We will be using the pretrained VGG model, so we have to normalize the images using the same values on which the pretrained model is trained.

The following code shows how we can do this. The code is mostly self-explanatory as we have already discussed it in detail in the previous chapters:

#Fixing the size of the image, reduce it further if you are not using a GPU.imsize = 512 is_cuda = torch.cuda.is_available()#Converting image ,making it suitable for training using the VGG model.prep = transforms.Compose([transforms.Resize(imsize),                           transforms.ToTensor(), transforms.Lambda(lambda x: x[torch.LongTensor([2,1,0])]), ...
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

Deep Learning with PyTorch

Deep Learning with PyTorch

Eli Stevens, Thomas Viehmann, Luca Pietro Giovanni Antiga
Grokking Deep Learning

Grokking Deep Learning

Andrew W. Trask

Publisher Resources

ISBN: 9781788624336Supplemental Content