-
Notifications
You must be signed in to change notification settings - Fork 4
/
dataloader.py
72 lines (51 loc) · 1.92 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import numpy as np
import os
import heartpy as hp
import copy
import random
from utils import normalize, beat_normalize
class TrainSet:
def __init__(self, folder):
self.train_data = np.load(os.path.join(folder, 'train.npy'))
def checkR(self, ecg):
working_data, measures = hp.process(ecg, 500.0)
peak_list = working_data['peaklist']
return peak_list
def __len__(self):
return self.train_data.shape[0]
def __getitem__(self, index):
ecg_instance = self.train_data[index]
r_index_list = self.checkR(ecg_instance[:,1])
r_idx = random.choice(r_index_list)
while r_idx < 200 or r_idx > 4800-400:
r_idx = random.choice(r_index_list)
beat = ecg_instance[r_idx-140:r_idx+340,:]
beat = beat_normalize(beat)
return beat, ecg_instance[100:4900,:]
class TestSet:
def __init__(self, folder):
self.train_data = np.load(os.path.join(folder, 'test.npy'))
def __len__(self):
return self.train_data.shape[0]
def checkR(self, ecg):
working_data, measures = hp.process(ecg, 500.0)
peak_list = working_data['peaklist']
return np.array(peak_list)
def __getitem__(self, index):
ecg_instance = self.train_data[index]
r_index = self.checkR(ecg_instance[:,1])
return r_index, ecg_instance
class PixelTestSet:
def __init__(self, folder):
self.train_data = np.load(os.path.join(folder, 'benchmark_data.npy'))
self.train_data = normalize(self.train_data)
def __len__(self):
return self.train_data.shape[0]
def checkR(self, ecg):
working_data, measures = hp.process(ecg, 500.0)
peak_list = working_data['peaklist']
return np.array(peak_list)
def __getitem__(self, index):
ecg_instance = self.train_data[index]
r_index = self.checkR(ecg_instance[:,1])
return r_index, ecg_instance