How to do it...

  1. First, we need to import all the necessary libraries:
import osfrom os import listdirfrom os.path import joinimport numpy as npimport randomimport matplotlib.pyplot as pltimport torchvisionfrom torchvision import transformsimport torchvision.datasets as datasetsimport torchimport torch.nn as nnimport torch.nn.functional as Fimport torch.optim as optimfrom torch.autograd import Variable
  1. In this recipe, we will be using the CelebA Faces dataset. We will import the data with a custom function in PyTorch:
class data_from_dir(data.Dataset):     def __init__(self, image_dir, transform=None):        super(DatasetFromFolder, self).__init__()        self.image_dir = image_dir        self.image_filenames = [ x for x in listdir(image_dir) if  is_image_file(x)] ...

Get Python Deep Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.