Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Deep Learning with PyTorch Workshop

You're reading from   The Deep Learning with PyTorch Workshop Build deep neural networks and artificial intelligence applications with PyTorch

Arrow left icon
Product type Paperback
Published in Jul 2020
Publisher Packt
ISBN-13 9781838989217
Length 330 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Hyatt Saleh Hyatt Saleh
Author Profile Icon Hyatt Saleh
Hyatt Saleh
Arrow right icon
View More author details
Toc

5. Style Transfer

Activity 5.01: Performing Style Transfer

Solution

  1. Import the required libraries:
    import numpy as np
    import torch
    from torch import nn, optim
    from PIL import Image
    import matplotlib.pyplot as plt
    from torchvision import transforms, models

    If your machine has a GPU available, make sure to define a variable named device that will help to allocate some variables to the GPU, as follows:

    device = "cuda"
  2. Specify the transformations to be performed over the input images. Be sure to resize them to the same size, convert them into tensors, and normalize them:
    imsize = 224
    loader = \
    transforms.Compose([transforms.Resize(imsize), \
                        transforms.ToTensor(),\
                        transforms.Normalize((0.485, 0.456, 0.406), \
       ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image