-
Notifications
You must be signed in to change notification settings - Fork 2
/
dataLoader.py
51 lines (38 loc) · 1.32 KB
/
dataLoader.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
import h5py
import torch.utils.data as data
import numpy as np
import torch
from warp import *
## Hyperparameter
WarpUpSampFactor = 0.707
#############
class DatasetFromFolder(data.Dataset):
def __init__(self, input_files, target_files):
super(DatasetFromFolder, self).__init__()
self.inputFile = h5py.File(input_files, 'r')
self.targetFile = h5py.File(target_files, 'r')
self.n_images = len(self.inputFile)
def __getitem__(self, index):
XfileName = 'X' + str(index)
YfileName = 'y' + str(index)
inputs = self.inputFile[XfileName]
inputs = inputs.value
inputs = np.float32(inputs)
inputs = inputs/255
#Warp Here
inputs = warp(inputs, WarpUpSampFactor)
inputs = np.moveaxis(inputs, 2, 0)
inputs = torch.from_numpy(inputs)
target = self.targetFile[YfileName]
target = target.value
target = np.float32(target)
target = target/255
#Warp Here
target = warp(target, WarpUpSampFactor)
target = np.moveaxis(target, 2, 0)
target = torch.from_numpy(target)
inputs = np.float32(inputs)
target = np.float32(target)
return inputs, target
def __len__(self):
return self.n_images