application_vnd.jupyter.stderr_output_2.png text_plain_output_3.png text_plain_output_1.png image_output_1.png
from PIL import Image

import torch

import torchvision.transforms as transforms

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

imsize = (512, 220) if torch.cuda.is_available() else (128, 220)
loader = transforms.Compose([transforms.Resize(imsize), transforms.ToTensor()])
def image_loader(image_name):
    image = Image.open(image_name)
    image = loader(image).unsqueeze(0)
    return image.to(device, torch.float)
style_img = image_loader('./style.jpg')
content_img = image_loader('./content.jpg')
print(style_img.size(), content_img.size())
assert style_img.size() == content_img.size(), 'we need to import style and content images of the same size'