This repository has been archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata_loader.py
49 lines (43 loc) · 1.73 KB
/
data_loader.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
from data_corrector import corrector
from torch.utils.data import Dataset, DataLoader
import random
import pickle
class loader(Dataset):
def __init__(self, path=None, params=None, index=None):
mode = params['mode']
a = corrector()
a.process(path)
self.data = a.data
self.label = a.label
self.window = a.time
self.r_peak = a.r_peak
total = len(self.label)
if index == None:
total = len(self.label)
index = list(range(total))
random.shuffle(index)
self.index = index
else:
self.index = index
if mode == 'training':
tmp = self.index[:int(0.7 * total)]
self.data = [self.data[i] for i in tmp]
self.label = [self.label[i] for i in tmp]
self.window = [self.window[i] for i in tmp]
self.r_peak = [self.r_peak[i] for i in tmp]
elif mode == 'test':
tmp = self.index[-int(0.2 * total):]
self.data = [self.data[i] for i in tmp]
self.label = [self.label[i] for i in tmp]
self.window = [self.window[i] for i in tmp]
self.r_peak = [self.r_peak[i] for i in tmp]
elif mode == 'eval':
tmp = self.index[-int(0.3 * total):-int(0.2 * total)]
self.data = [self.data[i] for i in tmp]
self.label = [self.label[i] for i in tmp]
self.window = [self.window[i] for i in tmp]
self.r_peak = [self.r_peak[i] for i in tmp]
def __getitem__(self, item):
return self.data[item], self.window[item], self.label[item], self.r_peak[item], item
def __len__(self):
return len(self.data)