-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustomascertain.py
67 lines (54 loc) · 1.94 KB
/
customascertain.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
import torch
import numpy as np
from torch.utils.data import Dataset, DataLoader
import pickle
import copy
# For each subject
#X, y = None, None
#for S in ["S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10", "S11", "S13", "S14", "S15", "S16", "S17"]:
#Xs = pickle.load(open("datasets/WESAD/splitted/X" + S + ".pkl", 'rb'), encoding='latin1')
#ys = pickle.load(open("datasets/WESAD/splitted/y" + S + ".pkl", 'rb'), encoding='latin1')
class ASCERTAINTrSet(Dataset):
def __init__(self, pair, transform=None):
self.root_dir = "datasets/ASCERTAIN_custom/splitted/"
self.transform = transform
self.pair = pair
subjs = [("S0", "S1"), ("S2", "S3"), ("S4", "S5"), ("S6", "S7"), ("S8", "S9"), ("S10", "S11"), ("S12", "S13"), ("S14", "S15"), ("S16", "")]
couple = subjs[self.pair]
X, y = None, None
for S in couple:
if S != "":
Xs = pickle.load(open(self.root_dir + "X" + S + ".pkl", 'rb'), encoding='latin1')
ys = pickle.load(open(self.root_dir + "y" + S + ".pkl", 'rb'), encoding='latin1')
if (X is None):
X = copy.deepcopy(Xs)
y = copy.deepcopy(ys)
else:
X = np.concatenate([X, Xs], axis = 0)
y = np.concatenate([y, ys], axis = 0)
del Xs
del ys
if self.transform:
X = self.transform(X)
self.data = X
self.targets = y
def __len__(self):
return len(self.data)
def __getitem__(self, idx):
data, target = self.data[idx], self.targets[idx]
return data, target
class ASCERTAINTsSet(Dataset):
def __init__(self, transform=None):
self.root_dir = "datasets/ASCERTAIN_custom/splitted/"
self.transform = transform
Xts = pickle.load(open(self.root_dir + "Xts.pkl", 'rb'), encoding='latin1')
yts = pickle.load(open(self.root_dir + "yts.pkl", 'rb'), encoding='latin1')
if self.transform:
Xts = self.transform(Xts)
self.data = Xts
self.targets = yts
def __len__(self):
return len(self.data)
def __getitem__(self, idx):
data, target = self.data[idx], self.targets[idx]
return data, target