-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata_loader.py
146 lines (112 loc) · 5.38 KB
/
data_loader.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import numpy as np
from PIL import Image, ImageChops
from torchvision import transforms
import random
import pdb
import torch
import torchvision.datasets as datasets
import torch.utils.data as data
class SYSUData(data.Dataset):
def __init__(self, data_dir, transform=None, colorIndex = None, thermalIndex = None):
# data_dir = '../Datasets/SYSU-MM01/'
# Load training images (path) and labels
train_color_image = np.load(data_dir + 'train_rgb_resized_img.npy')
self.train_color_label = np.load(data_dir + 'train_rgb_resized_label.npy')
train_thermal_image = np.load(data_dir + 'train_ir_resized_img.npy')
self.train_thermal_label = np.load(data_dir + 'train_ir_resized_label.npy')
# BGR to RGB
self.train_color_image = train_color_image
self.train_thermal_image = train_thermal_image
self.transform = transform
self.cIndex = colorIndex
self.tIndex = thermalIndex
def __getitem__(self, index):
img1, target1 = self.train_color_image[self.cIndex[index]], self.train_color_label[self.cIndex[index]]
img2, target2 = self.train_thermal_image[self.tIndex[index]], self.train_thermal_label[self.tIndex[index]]
img1 = self.transform(img1)
img2 = self.transform(img2)
return img1, img2, target1, target2
def __len__(self):
return len(self.train_color_label)
class RegDBData(data.Dataset):
def __init__(self, data_dir, trial, transform=None, colorIndex = None, thermalIndex = None):
# Load training images (path) and labels
# data_dir = '../Datasets/RegDB/'
train_color_list = data_dir + 'idx/train_visible_{}'.format(trial)+ '.txt'
train_thermal_list = data_dir + 'idx/train_thermal_{}'.format(trial)+ '.txt'
color_img_file, train_color_label = load_data(train_color_list)
thermal_img_file, train_thermal_label = load_data(train_thermal_list)
train_color_image = []
for i in range(len(color_img_file)):
img = Image.open(data_dir+ color_img_file[i])
img = img.resize((144, 288), Image.ANTIALIAS)
pix_array = np.array(img)
train_color_image.append(pix_array)
train_color_image = np.array(train_color_image)
train_thermal_image = []
for i in range(len(thermal_img_file)):
img = Image.open(data_dir+ thermal_img_file[i])
img = img.resize((144, 288), Image.ANTIALIAS)
pix_array = np.array(img)
train_thermal_image.append(pix_array)
train_thermal_image = np.array(train_thermal_image)
# BGR to RGB
self.train_color_image = train_color_image
self.train_color_label = train_color_label
# BGR to RGB
self.train_thermal_image = train_thermal_image
self.train_thermal_label = train_thermal_label
self.transform = transform
self.cIndex = colorIndex
self.tIndex = thermalIndex
def __getitem__(self, index):
img1, target1 = self.train_color_image[self.cIndex[index]], self.train_color_label[self.cIndex[index]]
img2, target2 = self.train_thermal_image[self.tIndex[index]], self.train_thermal_label[self.tIndex[index]]
img1 = self.transform(img1)
img2 = self.transform(img2)
return img1, img2, target1, target2
def __len__(self):
return len(self.train_color_label)
class TestData(data.Dataset):
def __init__(self, test_img_file, test_label, transform=None, img_size = (144,288)):
test_image = []
for i in range(len(test_img_file)):
img = Image.open(test_img_file[i])
img = img.resize((img_size[0], img_size[1]), Image.ANTIALIAS)
pix_array = np.array(img)
test_image.append(pix_array)
test_image = np.array(test_image)
self.test_image = test_image
self.test_label = test_label
self.transform = transform
def __getitem__(self, index):
img1, target1 = self.test_image[index], self.test_label[index]
img1 = self.transform(img1)
return img1, target1
def __len__(self):
return len(self.test_image)
class TestDataOld(data.Dataset):
def __init__(self, data_dir, test_img_file, test_label, transform=None, img_size = (144,288)):
test_image = []
for i in range(len(test_img_file)):
img = Image.open(data_dir + test_img_file[i])
img = img.resize((img_size[0], img_size[1]), Image.ANTIALIAS)
pix_array = np.array(img)
test_image.append(pix_array)
test_image = np.array(test_image)
self.test_image = test_image
self.test_label = test_label
self.transform = transform
def __getitem__(self, index):
img1, target1 = self.test_image[index], self.test_label[index]
img1 = self.transform(img1)
return img1, target1
def __len__(self):
return len(self.test_image)
def load_data(input_data_path ):
with open(input_data_path) as f:
data_file_list = open(input_data_path, 'rt').read().splitlines()
# Get full list of image and labels
file_image = [s.split(' ')[0] for s in data_file_list]
file_label = [int(s.split(' ')[1]) for s in data_file_list]
return file_image, file_label