-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_data.py
162 lines (113 loc) · 4.7 KB
/
custom_data.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
rom __future__ import print_function, division
import os
import torch
import pandas as pd
from skimage import io, transform
import numpy as np
import matplotlib.pyplot as plt
from torch.utils.data import Dataset, DataLoader
from torchvision import transforms, utils
# Ignore warnings
import warnings
warnings.filterwarnings("ignore")
class bpdata_train(Dataset):
def __init__(self, csv_file, root_dir, transform=None):
self.bp = pd.read_csv(csv_file, names = ['sbp','dbp','mbp','cla'])
self.root_dir = root_dir
self.transform = transform
self.to_tensor = transforms.ToTensor()
def __len__(self):
return len(self.bp)
def __getitem__(self, idx):
file_name = os.path.join(self.root_dir,'check%d.csv'%(idx+1))
patient_file = pd.read_csv(file_name,names = ['ppg','ecg'])
#patient_file = patient_file[['ppg','ecg']]
# patient_file=np.asarray(patient_file)
patient_file = np.asarray(patient_file)
# print(img_as_np.shape)
#patient_file = self.to_tensor(img_as_np)
#print(patient_file.shape)
#print(self.bp)
sbp_list = self.bp['sbp']
dbp_list = self.bp['dbp']
mbp_list = self.bp['mbp']
class_list = self.bp['cla']
#print(sbp_list[1])
sbp_data = sbp_list[idx]
dbp_data = dbp_list[idx]
mbp_data = mbp_list[idx]
class_data = class_list[idx]
#print(class_data)
sample = {'file': patient_file, 'sbp': sbp_data,'dbp': dbp_data,'mbp': mbp_data}
if self.transform:
sample = self.transform(sample)
return patient_file,mbp_data, class_data
# bp_dataset = bpdata(csv_file='/home/jeyamariajose/Projects/dl/bp.csv',
# root_dir='/home/jeyamariajose/Projects/dl/data/')
# train_loader = torch.utils.data.DataLoader(dataset=bp_dataset,
# batch_size=batch_size,
# shuffle=True)
# for i,(data,label) in enumerate(train_loader):
# print(label)
class bpdata_test(Dataset):
def __init__(self, csv_file, root_dir, transform=None):
self.bp = pd.read_csv(csv_file, names = ['sbp','dbp','mbp','cla'])
self.root_dir = root_dir
self.transform = transform
self.to_tensor = transforms.ToTensor()
def __len__(self):
return len(self.bp)
def __getitem__(self, idx):
file_name = os.path.join(self.root_dir,'check%d.csv'%(idx+4011))
patient_file = pd.read_csv(file_name,names = ['ppg','ecg'])
#patient_file = patient_file[['ppg','ecg']]
# patient_file=np.asarray(patient_file)
patient_file = np.asarray(patient_file)
# print(img_as_np.shape)
#patient_file = self.to_tensor(img_as_np)
#print(patient_file.shape)
#print(self.bp)
sbp_list = self.bp['sbp']
dbp_list = self.bp['dbp']
mbp_list = self.bp['mbp']
class_list = self.bp['cla']
#print(sbp_list[1])
sbp_data = sbp_list[idx]
dbp_data = dbp_list[idx]
mbp_data = mbp_list[idx]
class_data = class_list[idx]
sample = {'file': patient_file, 'sbp': sbp_data,'dbp': dbp_data,'mbp': mbp_data}
if self.transform:
sample = self.transform(sample)
return patient_file,mbp_data, class_data
class bpdata_val(Dataset):
def __init__(self, csv_file, root_dir, transform=None):
self.bp = pd.read_csv(csv_file, names = ['sbp','dbp','mbp','cla'])
self.root_dir = root_dir
self.transform = transform
self.to_tensor = transforms.ToTensor()
def __len__(self):
return len(self.bp)
def __getitem__(self, idx):
file_name = os.path.join(self.root_dir,'check%d.csv'%(idx+4512))
patient_file = pd.read_csv(file_name,names = ['ppg','ecg'])
#patient_file = patient_file[['ppg','ecg']]
# patient_file=np.asarray(patient_file)
patient_file = np.asarray(patient_file)
# print(img_as_np.shape)
#patient_file = self.to_tensor(img_as_np)
#print(patient_file.shape)
#print(self.bp)
sbp_list = self.bp['sbp']
dbp_list = self.bp['dbp']
mbp_list = self.bp['mbp']
class_list = self.bp['cla']
#print(sbp_list[1])
sbp_data = sbp_list[idx]
dbp_data = dbp_list[idx]
mbp_data = mbp_list[idx]
class_data = class_list[idx]
sample = {'file': patient_file, 'sbp': sbp_data,'dbp': dbp_data,'mbp': mbp_data}
if self.transform:
sample = self.transform(sample)
return patient_file,mbp_data, class_data