-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
51 lines (37 loc) · 1.23 KB
/
dataset.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
# -*- coding: utf-8 -*-
import torch.utils.data as data
import numpy as np
# define dataset
class anomaly_dataset(data.Dataset):
def __init__(self, data, target):
self.data = data
self.target = target
def __len__(self):
return len(self.data)
def pullitem(self, index):
# pull and normalize
img = self.data[index]
img -= np.mean(img)
img /= np.std(img)
target = self.target[index]
target -= np.mean(target)
target /= np.std(target)
return img, target
def __getitem__(self, index):
img, target = self.pullitem(index)
return img, target
class classify_anomaly_dataset(data.Dataset):
def __init__(self, data, target):
self.data = data
self.target = target
def __len__(self):
return len(self.data)
def pullitem(self, index):
# pull and normalize
img = self.data[index]
img -= np.mean(img)
img /= np.std(img)
return img
def __getitem__(self, index):
img = self.pullitem(index)
return img, self.target[index]