-
Notifications
You must be signed in to change notification settings - Fork 3
/
dataset.py
61 lines (42 loc) · 2.12 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
52
53
54
55
56
57
58
59
import os
import numpy as np
from torch.utils.data import Dataset
import matplotlib.pyplot as plt
import scipy.io
class MyDataset_source(Dataset):
def __init__(self, mode='train'):
super(MyDataset_source, self).__init__()
if mode == 'train':
self.data = scipy.io.loadmat(os.path.join(os.getcwd(), 'data/Training_Data_Florence.mat'))['Training_Data']
self.labels = scipy.io.loadmat(os.path.join(os.getcwd(), 'data/Training_Label_Florence.mat'))['Training_Label']
self.data = self.data.transpose((0,3,1,2))
elif mode == 'test':
self.data = scipy.io.loadmat(os.path.join(os.getcwd(), 'data/Testing_Data_Florence.mat'))['Testing_Data']
self.labels = scipy.io.loadmat(os.path.join(os.getcwd(), 'data/Testing_Label_Florence.mat'))['Testing_Label']
self.data = self.data.transpose((0,3,1,2))
self.num = len(self.labels)
def __len__(self):
return self.num
def __getitem__(self, index):
return self.data[index, :], self.labels[index]
class MyDataset_target(Dataset):
def __init__(self, mode='train'):
super(MyDataset_target, self).__init__()
if mode == 'train':
self.data = scipy.io.loadmat(os.path.join(os.getcwd(), 'data/Training_Data_ottawa.mat'))['Training_Data']
self.labels = scipy.io.loadmat(os.path.join(os.getcwd(), 'data/Training_Label_ottawa.mat'))['Training_Label']
self.data = self.data.transpose((0,3,1,2))
elif mode == 'test':
self.data = scipy.io.loadmat(os.path.join(os.getcwd(), 'data/Testing_Data_ottawa.mat'))['Testing_Data']
self.labels = scipy.io.loadmat(os.path.join(os.getcwd(), 'data/Testing_Label_ottawa.mat'))['Testing_Label']
self.data = self.data.transpose((0,3,1,2))
self.num = len(self.labels)
def __len__(self):
return self.num
def __getitem__(self, index):
return self.data[index, :], self.labels[index]
def unpickle(file):
import pickle
with open(file, 'rb') as fo:
dict = pickle.load(fo, encoding='bytes')
return dict