- 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
- 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)] ...