-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustom dataset for ECG
32 lines (29 loc) · 1.03 KB
/
Custom dataset for ECG
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
class Custom_dataset(Dataset):
def __init__(self, data_dir, transform=ToTensor()):
self.all_files = []
files = glob.glob(data_dir + '/*.csv')
for f in files:
temp_df = pd.read_csv(f,sep=" ")
self.all_files.append(temp_df)
def __len__(self):
return len(self.all_files)
def __getitem__(self,idx):
all_input_tensors = []
all_output_tensors = []
#turn list of dataframes into Tensor
for files in self.all_files:
temp_df=pd.read_csv(f,sep=" ")
input_tensor=df.iloc[:,1]
input_tensor = torch.tensor(input_tensor)
all_input_tensors.append(input_tensor)
#output_tensor=df.iloc[:,2:3]
output_tensor=df.iloc[:,2:9].values
output_tensor=torch.tensor(output_tensor)
all_output_tensors.append(output_tensor)
X=torch.stack(all_input_tensors)
y=torch.stack(all_output_tensors)
Sample = X,y
return Sample
if __name__ == "__main__":
data_dir = "/content/CSV_data"
dataset = Custom_dataset(data_dir)