-
Notifications
You must be signed in to change notification settings - Fork 1
/
dataset.py
56 lines (33 loc) · 1.71 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import torchvision.transforms as T
from torch.utils.data import Dataset
import os
from PIL import Image
class RainDataset(Dataset):
def __init__(self, gt_path, ip_path, img_size = 64):
super().__init__()
self.gt_fnames = [os.path.join(gt_path, f) for f in sorted(os.listdir(gt_path))]
self.ip_fnames = [os.path.join(ip_path, f) for f in sorted(os.listdir(ip_path))]
self.transform = T.Compose([T.CenterCrop((img_size, img_size)),
T.ToTensor(),
T.Normalize([0.0,0.0,0.0],[1.0,1.0,1.0])])
def __len__(self):
return len(self.gt_fnames)
def __getitem__(self, idx):
ip_img = Image.open(self.ip_fnames[idx]).convert('RGB')
gt_img = Image.open(self.gt_fnames[idx]).convert('RGB')
ip_img = self.transform(ip_img)
gt_img = self.transform(gt_img)
return ip_img, gt_img
class TestDataset(Dataset):
def __init__(self, ip_path, img_size = 64):
super().__init__()
self.ip_fnames = [os.path.join(ip_path, f) for f in sorted(os.listdir(ip_path))]
self.transform = T.Compose([T.CenterCrop((img_size, img_size)),
T.ToTensor(),
T.Normalize([0.0,0.0,0.0],[1.0,1.0,1.0])])
def __len__(self):
return len(self.gt_fnames)
def __getitem__(self, idx):
ip_img = Image.open(self.ip_fnames[idx]).convert('RGB')
ip_img = self.transform(ip_img)
return ip_img