-
Notifications
You must be signed in to change notification settings - Fork 3
/
data_processor.py
32 lines (24 loc) · 947 Bytes
/
data_processor.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
import torch
import platform
import h5py
def data_loader(args):
if (platform.system() == "Windows"):
num_workers = 0
else:
num_workers = 4
kwopt = {'num_workers': num_workers, 'pin_memory': True}
Training_data_Name = 'traindata0-255.mat'
f = h5py.File('./DataSets/%s' % Training_data_Name, 'r')
Training_data = f['inputs'][:]
Training_lable = Training_data
class RandomDataset(torch.utils.data.Dataset):
def __init__(self, data, length):
self.data = data
self.len = length
def __getitem__(self, index):
return torch.Tensor(self.data[index, :, :, :]).float()
def __len__(self):
return self.len
trn_loader = torch.utils.data.DataLoader(dataset=RandomDataset(Training_lable, 89600), batch_size=args.batch_size,
shuffle=True, **kwopt, drop_last=False)
return trn_loader