-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
36 lines (25 loc) · 1007 Bytes
/
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
"""
Creating the Training Set
Creating the pytorch dataset class for use with Data Loader to enable batch training of the GAN
"""
import torch
from torch.utils.data import Dataset, DataLoader
import pandas as pd
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
class SineData(Dataset):
#This is the class for teh ECG Data that we need to load, transform and then use in teh dataloader.
def __init__(self,source_file,transform = None):
self.source_file = source_file
self.data = pd.read_csv(source_file, header = None)
self.transform = transform
def __len__(self):
return self.data.shape[0]
def __getitem__(self,idx):
sample = self.data.iloc[idx]
if self.transform:
sample = self.transform(sample)
return sample
"""Including the function that will transform the dataframe to a pytorch tensor"""
class PD_to_Tensor(object):
def __call__(self,sample):
return torch.tensor(sample.values).cuda()