forked from HasnainRaz/Fast-AgingGAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
27 lines (19 loc) · 891 Bytes
/
dataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
from PIL import Image
from torch.utils.data import Dataset
class ImagetoImageDataset(Dataset):
def __init__(self, domainA_dir, domainB_dir, transforms=None):
self.imagesA = [os.path.join(domainA_dir, x) for x in os.listdir(domainA_dir) if
x.endswith('.png') or x.endswith('jpg')]
self.imagesB = [os.path.join(domainB_dir, x) for x in os.listdir(domainB_dir) if
x.endswith('.png') or x.endswith('jpg')]
self.transforms = transforms
def __len__(self):
return min(len(self.imagesA), len(self.imagesB))
def __getitem__(self, idx):
imageA = Image.open(self.imagesA[idx])
imageB = Image.open(self.imagesB[idx])
if self.transforms is not None:
imageA = self.transforms(imageA)
imageB = self.transforms(imageB)
return imageA, imageB