-
Notifications
You must be signed in to change notification settings - Fork 0
/
physionet2012.py
51 lines (41 loc) · 1.25 KB
/
physionet2012.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
import numpy as np
import pdb
# data loader
path = 'physionet2012/'
def load_data(tasks=None):
if tasks == None:
task_set = [0,1,2,3]
else:
task_set = tasks
# Get data
data = np.load(path+'x.npy')
label = np.load(path+'y.npy')
label = label[:,task_set]
inp = np.array(data)
label = np.array(label)
index = range(len(label))
# np.random.shuffle(index)
train = int(len(label)*0.7)
valid = int(len(label)*0.8)
train_x = []
train_y = []
for i in range(train):
train_x.append(inp[index[i]])
train_y.append(label[index[i]])
train_x = np.array(train_x,np.float32)
train_y = np.array(train_y,np.float32)
valid_x = []
valid_y = []
for i in range(train,valid):
valid_x.append(inp[index[i]])
valid_y.append(label[index[i]])
valid_x = np.array(valid_x,np.float32)
valid_y = np.array(valid_y,np.float32)
eval_x = []
eval_y = []
for i in range(valid,len(index)):
eval_x.append(inp[index[i]])
eval_y.append(label[index[i]])
eval_x = np.array(eval_x,np.float32)
eval_y = np.array(eval_y,np.float32)
return train_x, train_y, valid_x, valid_y, eval_x, eval_y, train_x.shape[2], train_x.shape[1], len(task_set)