I'm trying to train a GAN to colorize images. For that, I'm using ImageFolder
of torchvision
to load grayscale images but I also need the original data alongwith the transformed ones.
I want it in the fastest way as the data is large. I want to make ImageFolder
load both at the same time to reduce the time complexity.
def load_data_bw(opt):
datapath = '/content/gdrive/My Drive/faces/2003'
dataset = torchvision.datasets.ImageFolder(datapath,
transform=transforms.Compose([
transforms.Grayscale(num_output_channels=3), #load images as grayscale with three channels
transforms.RandomChoice(
[transforms.Resize(opt['loadSize'], interpolation=1),
transforms.Resize(opt['loadSize'], interpolation=2),
transforms.Resize(opt['loadSize'], interpolation=3),
transforms.Resize((opt['loadSize'], opt['loadSize']),
interpolation=1),
transforms.Resize((opt['loadSize'], opt['loadSize']),
interpolation=2),
transforms.Resize((opt['loadSize'], opt['loadSize']),
interpolation=3)]
),
transforms.RandomChoice(
[transforms.RandomResizedCrop(opt['fineSize'], interpolation=1),
transforms.RandomResizedCrop(opt['fineSize'], interpolation=2),
transforms.RandomResizedCrop(opt['fineSize'], interpolation=3)]
),
transforms.ColorJitter(brightness=0.1, contrast=0.1),
transforms.RandomHorizontalFlip(),
transforms.ToTensor()
]))
return dataset
I'm expecting to get:
for iteration, orig_data, gray_data in enumerate(training_data_loader, 1):
# code..
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…