Loading original images besides the transformed ones using ImageFolder

后端 未结 1 511
暗喜
暗喜 2021-01-24 21:38

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 da

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-24 22:23

    I assume you have 2 dataset variables i.e. dataset_bw and dataset_color that you can load as you mention using ImageFolder. Then you could do the following :

    class GAN_dataset(Dataset):
        def __init__(self, dataset_bw, dataset_color):
            self.dataset1 = dataset_bw
            self.dataset2 = dataset_color
    
        def __getitem__(self, index):
            x1 = self.dataset1[index]
            x2 = self.dataset2[index]
    
            return x1, x2
    
        def __len__(self):
            return len(self.dataset1)
    
    dataset = GAN_dataset(dataset_bw, dataset_color)
    loader = DataLoader(dataset, batch_size = ...)
    

    This way you when you iterate through loader, you will get two images as you require.

    0 讨论(0)
提交回复
热议问题