-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasets.py
76 lines (55 loc) · 2.62 KB
/
datasets.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import torch
import numpy as np
from torch.utils.data import Dataset
import glob
import os
from torch.utils.data.dataloader import DataLoader
class TrainDataset(Dataset):
def __init__(self, LR_phiG_folder, HR_phi_folder):
# super(TrainDataset, self).__init__()
self.LR_phiG_list = glob.glob(LR_phiG_folder+'*')
self.HR_phi_folder = HR_phi_folder
self.data_len = len(self.LR_phiG_list)
def __getitem__(self, idx):
single_LR_phiG_path = self.LR_phiG_list[idx]
LR_phiG_as_np = np.load(single_LR_phiG_path)
LR_phiG_as_ten = torch.from_numpy(LR_phiG_as_np).float()
file_name = os.path.split(single_LR_phiG_path)[1]
single_HR_phi_path = self.HR_phi_folder + file_name
HR_phi_as_np = np.load(single_HR_phi_path)
HR_phi_as_np = HR_phi_as_np/(500/(2*np.pi))
HR_phi_as_np = np.expand_dims(HR_phi_as_np, 0)
HR_phi_as_ten = torch.from_numpy(HR_phi_as_np).float()
return LR_phiG_as_ten, HR_phi_as_ten
def __len__(self):
return self.data_len
class EvalDataset(Dataset):
def __init__(self, LR_phiG_folder, HR_phi_folder):
# super(TrainDataset, self).__init__()
self.LR_phiG_list = glob.glob(LR_phiG_folder+'*')
self.HR_phi_folder = HR_phi_folder
self.data_len = len(self.LR_phiG_list)
def __getitem__(self, idx):
single_LR_phiG_path = self.LR_phiG_list[idx]
LR_phiG_as_np = np.load(single_LR_phiG_path)
LR_phiG_as_ten = torch.from_numpy(LR_phiG_as_np).float()
file_name = os.path.split(single_LR_phiG_path)[1]
single_HR_phi_path = self.HR_phi_folder + file_name
HR_phi_as_np = np.load(single_HR_phi_path)
HR_phi_as_np = HR_phi_as_np/(500/(2*np.pi))
HR_phi_as_np = np.expand_dims(HR_phi_as_np, 0)
HR_phi_as_ten = torch.from_numpy(HR_phi_as_np).float()
return LR_phiG_as_ten, HR_phi_as_ten
def __len__(self):
return self.data_len
# if __name__ == "__main__":
# LR_phiG_folder = '/home/vicky/soapy/Dataset_254x254/Train/LR_phigrad/'
# HR_phi_folder = '/home/vicky/soapy/Dataset_254x254/Train/HR_phi/'
# train_dataset = TrainDataset(LR_phiG_folder, HR_phi_folder)
# train_dataloader = DataLoader(dataset=train_dataset,
# batch_size=2,
# shuffle=True,
# num_workers=2,
# pin_memory=True)
# for images, labels in train_dataloader:
# break