5. Style Transfer
Activity 5.01: Performing Style Transfer
Solution
- 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"
- 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), \ ...