-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataloader_custom.py
32 lines (24 loc) · 968 Bytes
/
dataloader_custom.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
# Author: Mubarak Abdu-Aguye <[email protected]>
# License: BSD-3-Clause
import numpy as np
class UCRTSLoader(object):
def __init__(self, filename, pytorch_compatible=False):
super(UCRTSLoader).__init__()
self.fn = filename
self.data = np.loadtxt(self.fn, delimiter=",")
self.class_labels = sorted(set(self.data[:,0].astype(int)))
self.n_classes = len(self.class_labels)
self.class_map = {self.class_labels[n]: n for n in range(self.n_classes)}
self.pytorch_compatible = pytorch_compatible
def __getitem__(self, index):
datum = self.data[index]
label = int(datum[0])
data = datum[1:]
if not self.pytorch_compatible:
#inject custom logic here
data = data[:,np.newaxis]
else:
data = data[np.newaxis,:]
return (data, self.class_map[label])
def __len__(self):
return len(self.data)