-
Notifications
You must be signed in to change notification settings - Fork 30
/
gtav.py
executable file
·619 lines (518 loc) · 24.7 KB
/
gtav.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
"""
GTAV Dataset Loader
"""
import logging
import json
import os
import numpy as np
from PIL import Image
from skimage import color
from torch.utils import data
import torch
import torchvision.transforms as transforms
import datasets.uniform as uniform
import datasets.cityscapes_labels as cityscapes_labels
import scipy.misc as m
from config import cfg
trainid_to_name = cityscapes_labels.trainId2name
id_to_trainid = cityscapes_labels.label2trainid
trainid_to_trainid = cityscapes_labels.trainId2trainId
color_to_trainid = cityscapes_labels.color2trainId
num_classes = 19
ignore_label = 255
root = cfg.DATASET.GTAV_DIR
img_postfix = '.png'
palette = [128, 64, 128, 244, 35, 232, 70, 70, 70, 102, 102, 156, 190, 153, 153,
153, 153, 153, 250, 170, 30,
220, 220, 0, 107, 142, 35, 152, 251, 152, 70, 130, 180, 220, 20, 60,
255, 0, 0, 0, 0, 142, 0, 0, 70,
0, 60, 100, 0, 80, 100, 0, 0, 230, 119, 11, 32]
zero_pad = 256 * 3 - len(palette)
for i in range(zero_pad):
palette.append(0)
def colorize_mask(mask):
"""
Colorize a segmentation mask.
"""
# mask: numpy array of the mask
new_mask = Image.fromarray(mask.astype(np.uint8)).convert('P')
new_mask.putpalette(palette)
return new_mask
def add_items(items, aug_items, cities, img_path, mask_path, mask_postfix, mode, maxSkip):
"""
Add More items ot the list from the augmented dataset
"""
for c in cities:
c_items = [name.split(img_postfix)[0] for name in
os.listdir(os.path.join(img_path, c))]
for it in c_items:
item = (os.path.join(img_path, c, it + img_postfix),
os.path.join(mask_path, c, it + mask_postfix))
# ########################################################
# ###### dataset augmentation ############################
# ########################################################
# if mode == "train" and maxSkip > 0:
# new_img_path = os.path.join(aug_root, 'leftImg8bit_trainvaltest', 'leftImg8bit')
# new_mask_path = os.path.join(aug_root, 'gtFine_trainvaltest', 'gtFine')
# file_info = it.split("_")
# cur_seq_id = file_info[-1]
# prev_seq_id = "%06d" % (int(cur_seq_id) - maxSkip)
# next_seq_id = "%06d" % (int(cur_seq_id) + maxSkip)
# prev_it = file_info[0] + "_" + file_info[1] + "_" + prev_seq_id
# next_it = file_info[0] + "_" + file_info[1] + "_" + next_seq_id
# prev_item = (os.path.join(new_img_path, c, prev_it + img_postfix),
# os.path.join(new_mask_path, c, prev_it + mask_postfix))
# if os.path.isfile(prev_item[0]) and os.path.isfile(prev_item[1]):
# aug_items.append(prev_item)
# next_item = (os.path.join(new_img_path, c, next_it + img_postfix),
# os.path.join(new_mask_path, c, next_it + mask_postfix))
# if os.path.isfile(next_item[0]) and os.path.isfile(next_item[1]):
# aug_items.append(next_item)
items.append(item)
# items.extend(extra_items)
def make_cv_splits(img_dir_name):
"""
Create splits of train/valid data.
A split is a lists of cities.
split0 is aligned with the default Cityscapes train/valid.
"""
trn_path = os.path.join(root, img_dir_name, 'train')
val_path = os.path.join(root, img_dir_name, 'valid')
trn_cities = ['train/' + c for c in os.listdir(trn_path)]
val_cities = ['valid/' + c for c in os.listdir(val_path)]
# want reproducible randomly shuffled
trn_cities = sorted(trn_cities)
all_cities = val_cities + trn_cities
num_val_cities = len(val_cities)
num_cities = len(all_cities)
cv_splits = []
for split_idx in range(cfg.DATASET.CV_SPLITS):
split = {}
split['train'] = []
split['val'] = []
offset = split_idx * num_cities // cfg.DATASET.CV_SPLITS
for j in range(num_cities):
if j >= offset and j < (offset + num_val_cities):
split['val'].append(all_cities[j])
else:
split['train'].append(all_cities[j])
cv_splits.append(split)
return cv_splits
def make_split_coarse(img_path):
"""
Create a train/valid split for coarse
return: city split in train
"""
all_cities = os.listdir(img_path)
all_cities = sorted(all_cities) # needs to always be the same
val_cities = [] # Can manually set cities to not be included into train split
split = {}
split['val'] = val_cities
split['train'] = [c for c in all_cities if c not in val_cities]
return split
def make_test_split(img_dir_name):
test_path = os.path.join(root, img_dir_name, 'leftImg8bit', 'test')
test_cities = ['test/' + c for c in os.listdir(test_path)]
return test_cities
def make_dataset(mode, maxSkip=0, cv_split=0):
"""
Assemble list of images + mask files
fine - modes: train/valid/test/trainval cv:0,1,2
coarse - modes: train/valid cv:na
path examples:
leftImg8bit_trainextra/leftImg8bit/train_extra/augsburg
gtCoarse/gtCoarse/train_extra/augsburg
"""
items = []
aug_items = []
assert mode in ['train', 'val', 'test', 'trainval']
img_dir_name = 'images'
img_path = os.path.join(root, img_dir_name)
mask_path = os.path.join(root, 'labels')
mask_postfix = '.png'
cv_splits = make_cv_splits(img_dir_name)
if mode == 'trainval':
modes = ['train', 'val']
else:
modes = [mode]
for mode in modes:
logging.info('{} fine cities: '.format(mode) + str(cv_splits[cv_split][mode]))
add_items(items, aug_items, cv_splits[cv_split][mode], img_path, mask_path,
mask_postfix, mode, maxSkip)
# logging.info('Cityscapes-{}: {} images'.format(mode, len(items)))
logging.info('GTAV-{}: {} images'.format(mode, len(items) + len(aug_items)))
return items, aug_items
class GTAV(data.Dataset):
def __init__(self, mode, maxSkip=0, joint_transform=None, sliding_crop=None,
transform=None, target_transform=None, target_aux_transform=None, dump_images=False,
cv_split=None, eval_mode=False,
eval_scales=None, eval_flip=False, image_in=False,
extract_feature=False):
self.mode = mode
self.maxSkip = maxSkip
self.joint_transform = joint_transform
self.sliding_crop = sliding_crop
self.transform = transform
self.target_transform = target_transform
self.target_aux_transform = target_aux_transform
self.dump_images = dump_images
self.eval_mode = eval_mode
self.eval_flip = eval_flip
self.eval_scales = None
self.image_in = image_in
self.extract_feature = extract_feature
if eval_scales != None:
self.eval_scales = [float(scale) for scale in eval_scales.split(",")]
if cv_split:
self.cv_split = cv_split
assert cv_split < cfg.DATASET.CV_SPLITS, \
'expected cv_split {} to be < CV_SPLITS {}'.format(
cv_split, cfg.DATASET.CV_SPLITS)
else:
self.cv_split = 0
self.imgs, _ = make_dataset(mode, self.maxSkip, cv_split=self.cv_split)
if len(self.imgs) == 0:
raise RuntimeError('Found 0 images, please check the data set')
self.mean_std = ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
def _eval_get_item(self, img, mask, scales, flip_bool):
return_imgs = []
for flip in range(int(flip_bool) + 1):
imgs = []
if flip:
img = img.transpose(Image.FLIP_LEFT_RIGHT)
for scale in scales:
w, h = img.size
target_w, target_h = int(w * scale), int(h * scale)
resize_img = img.resize((target_w, target_h))
tensor_img = transforms.ToTensor()(resize_img)
final_tensor = transforms.Normalize(*self.mean_std)(tensor_img)
imgs.append(final_tensor)
return_imgs.append(imgs)
return return_imgs, mask
def __getitem__(self, index):
img_path, mask_path = self.imgs[index]
img, mask = Image.open(img_path).convert('RGB'), m.imread(mask_path)
img_name = os.path.splitext(os.path.basename(img_path))[0]
while (img.size[1], img.size[0]) != mask[:,:,0].shape:
print("Error!!", img.size, mask[:,:,0].shape, img_name)
print("Dropping ", str(index))
# index = index + 1
if index + 1 == len(self.imgs):
index = 0
else:
index += 1
img_path, mask_path = self.imgs[index]
img, mask = Image.open(img_path).convert('RGB'), m.imread(mask_path)
img_name = os.path.splitext(os.path.basename(img_path))[0]
image_size = mask[:,:,0].shape
mask_copy = np.full(image_size, ignore_label, dtype=np.uint8)
for k, v in color_to_trainid.items():
if v != 255 and v != -1:
mask_copy[(mask == np.array(k))[:,:,0] & (mask == np.array(k))[:,:,1] & (mask == np.array(k))[:,:,2]] = v
# for k, v in color_to_trainid.items():
# mask_copy[(mask == np.array(k))[:,:,0]] = v
if self.eval_mode:
return [transforms.ToTensor()(img)], self._eval_get_item(img, mask_copy,
self.eval_scales,
self.eval_flip), img_name
mask = Image.fromarray(mask_copy.astype(np.uint8))
# Image Transformations
if self.extract_feature is not True:
if self.joint_transform is not None:
img, mask = self.joint_transform(img, mask)
if self.transform is not None:
img = self.transform(img)
rgb_mean_std_gt = ([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])
img_gt = transforms.Normalize(*rgb_mean_std_gt)(img)
rgb_mean_std = ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
if self.image_in:
eps = 1e-5
rgb_mean_std = ([torch.mean(img[0]), torch.mean(img[1]), torch.mean(img[2])],
[torch.std(img[0])+eps, torch.std(img[1])+eps, torch.std(img[2])+eps])
img = transforms.Normalize(*rgb_mean_std)(img)
if self.target_aux_transform is not None:
mask_aux = self.target_aux_transform(mask)
else:
mask_aux = torch.tensor([0])
if self.target_transform is not None:
mask = self.target_transform(mask)
# Debug
if self.dump_images:
outdir = '../../dump_imgs_{}'.format(self.mode)
os.makedirs(outdir, exist_ok=True)
out_img_fn = os.path.join(outdir, img_name + '.png')
out_msk_fn = os.path.join(outdir, img_name + '_mask.png')
mask_img = colorize_mask(np.array(mask))
img.save(out_img_fn)
mask_img.save(out_msk_fn)
return img, mask, img_name, mask_aux
def __len__(self):
return len(self.imgs)
class GTAVUniform(data.Dataset):
"""
Please do not use this for AGG
"""
def __init__(self, mode, maxSkip=0, joint_transform_list=None, sliding_crop=None,
transform=None, target_transform=None, target_aux_transform=None, dump_images=False,
cv_split=None, class_uniform_pct=0.5, class_uniform_tile=1024,
test=False, coarse_boost_classes=None, is_additional=False, image_in=False,
extract_feature=False):
self.mode = mode
self.maxSkip = maxSkip
self.joint_transform_list = joint_transform_list
self.sliding_crop = sliding_crop
self.transform = transform
self.target_transform = target_transform
self.target_aux_transform = target_aux_transform
self.dump_images = dump_images
self.class_uniform_pct = class_uniform_pct
self.class_uniform_tile = class_uniform_tile
self.coarse_boost_classes = coarse_boost_classes
self.is_additional = is_additional
self.image_in = image_in
self.extract_feature = extract_feature
if cv_split:
self.cv_split = cv_split
assert cv_split < cfg.DATASET.CV_SPLITS, \
'expected cv_split {} to be < CV_SPLITS {}'.format(
cv_split, cfg.DATASET.CV_SPLITS)
else:
self.cv_split = 0
self.imgs, self.aug_imgs = make_dataset(mode, self.maxSkip, cv_split=self.cv_split)
assert len(self.imgs), 'Found 0 images, please check the data set'
# Centroids for fine data
json_fn = 'gtav_{}_cv{}_tile{}.json'.format(
self.mode, self.cv_split, self.class_uniform_tile)
if os.path.isfile(json_fn):
with open(json_fn, 'r') as json_data:
centroids = json.load(json_data)
for idx in centroids:
print("###### centroids", idx)
self.centroids = {int(idx): centroids[idx] for idx in centroids}
else:
self.centroids = uniform.class_centroids_all_from_color(
self.imgs,
num_classes,
id2trainid=color_to_trainid,
tile_size=class_uniform_tile)
with open(json_fn, 'w') as outfile:
json.dump(self.centroids, outfile, indent=4)
self.fine_centroids = self.centroids.copy()
self.build_epoch()
def cities_uniform(self, imgs, name):
""" list out cities in imgs_uniform """
cities = {}
for item in imgs:
img_fn = item[0]
img_fn = os.path.basename(img_fn)
city = img_fn.split('_')[0]
cities[city] = 1
city_names = cities.keys()
logging.info('Cities for {} '.format(name) + str(sorted(city_names)))
def build_epoch(self, cut=False):
"""
Perform Uniform Sampling per epoch to create a new list for training such that it
uniformly samples all classes
"""
if self.class_uniform_pct > 0:
if self.is_additional:
if cut:
# after max_cu_epoch, we only fine images to fine tune
self.imgs_uniform = uniform.build_epoch(self.imgs,
self.fine_centroids,
num_classes,
cfg.CLASS_UNIFORM_PCT_ADD)
else:
self.imgs_uniform = uniform.build_epoch(self.imgs + self.aug_imgs,
self.centroids,
num_classes,
cfg.CLASS_UNIFORM_PCT_ADD)
else:
if cut:
# after max_cu_epoch, we only fine images to fine tune
self.imgs_uniform = uniform.build_epoch(self.imgs,
self.fine_centroids,
num_classes,
cfg.CLASS_UNIFORM_PCT)
else:
self.imgs_uniform = uniform.build_epoch(self.imgs + self.aug_imgs,
self.centroids,
num_classes,
cfg.CLASS_UNIFORM_PCT)
else:
self.imgs_uniform = self.imgs
def __getitem__(self, index):
elem = self.imgs_uniform[index]
centroid = None
if len(elem) == 4:
img_path, mask_path, centroid, class_id = elem
else:
img_path, mask_path = elem
img, mask = Image.open(img_path).convert('RGB'), m.imread(mask_path)
img_name = os.path.splitext(os.path.basename(img_path))[0]
# print(img.size, mask[:,:,0].shape)
while (img.size[1], img.size[0]) != mask[:,:,0].shape:
print("Error!!", img.size, mask[:,:,0].shape, img_name)
print("Dropping ", str(index))
# index = index + 1
if index + 1 == len(self.imgs):
index = 0
else:
index += 1
img_path, mask_path = self.imgs[index]
img, mask = Image.open(img_path).convert('RGB'), m.imread(mask_path)
img_name = os.path.splitext(os.path.basename(img_path))[0]
image_size = mask[:,:,0].shape
mask_copy = np.full(image_size, ignore_label, dtype=np.uint8)
for k, v in color_to_trainid.items():
if v != 255 and v != -1:
mask_copy[(mask == np.array(k))[:,:,0] & (mask == np.array(k))[:,:,1] & (mask == np.array(k))[:,:,2]] = v
# for k, v in color_to_trainid.items():
# mask_copy[(mask == np.array(k))[:,:,0]] = v
mask = Image.fromarray(mask_copy.astype(np.uint8))
# mask = np.array(mask)
# mask_copy = mask.copy()
# for k, v in trainid_to_trainid.items():
# mask_copy[mask == k] = v
# mask = Image.fromarray(mask_copy.astype(np.uint8))
# Image Transformations
if self.extract_feature is not True:
if self.joint_transform_list is not None:
for idx, xform in enumerate(self.joint_transform_list):
if idx == 0 and centroid is not None:
# HACK
# We assume that the first transform is capable of taking
# in a centroid
img, mask = xform(img, mask, centroid)
else:
img, mask = xform(img, mask)
# Debug
if self.dump_images and centroid is not None:
outdir = '../../dump_imgs_{}'.format(self.mode)
os.makedirs(outdir, exist_ok=True)
dump_img_name = trainid_to_name[class_id] + '_' + img_name
out_img_fn = os.path.join(outdir, dump_img_name + '.png')
out_msk_fn = os.path.join(outdir, dump_img_name + '_mask.png')
mask_img = colorize_mask(np.array(mask))
img.save(out_img_fn)
mask_img.save(out_msk_fn)
if self.transform is not None:
img = self.transform(img)
rgb_mean_std_gt = ([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])
img_gt = transforms.Normalize(*rgb_mean_std_gt)(img)
rgb_mean_std = ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
if self.image_in:
eps = 1e-5
rgb_mean_std = ([torch.mean(img[0]), torch.mean(img[1]), torch.mean(img[2])],
[torch.std(img[0])+eps, torch.std(img[1])+eps, torch.std(img[2])+eps])
img = transforms.Normalize(*rgb_mean_std)(img)
if self.target_aux_transform is not None:
mask_aux = self.target_aux_transform(mask)
else:
mask_aux = torch.tensor([0])
if self.target_transform is not None:
mask = self.target_transform(mask)
return img, mask, img_name, mask_aux
def __len__(self):
return len(self.imgs_uniform)
class GTAVAug(data.Dataset):
def __init__(self, mode, maxSkip=0, joint_transform=None, sliding_crop=None,
transform=None, color_transform=None, geometric_transform=None, target_transform=None, target_aux_transform=None, dump_images=False,
cv_split=None, eval_mode=False,
eval_scales=None, eval_flip=False, image_in=False,
extract_feature=False):
self.mode = mode
self.maxSkip = maxSkip
self.joint_transform = joint_transform
self.sliding_crop = sliding_crop
self.transform = transform
self.color_transform = color_transform
self.geometric_transform = geometric_transform
self.target_transform = target_transform
self.target_aux_transform = target_aux_transform
self.dump_images = dump_images
self.eval_mode = eval_mode
self.eval_flip = eval_flip
self.eval_scales = None
self.image_in = image_in
self.extract_feature = extract_feature
if eval_scales != None:
self.eval_scales = [float(scale) for scale in eval_scales.split(",")]
if cv_split:
self.cv_split = cv_split
assert cv_split < cfg.DATASET.CV_SPLITS, \
'expected cv_split {} to be < CV_SPLITS {}'.format(
cv_split, cfg.DATASET.CV_SPLITS)
else:
self.cv_split = 0
self.imgs, _ = make_dataset(mode, self.maxSkip, cv_split=self.cv_split)
if len(self.imgs) == 0:
raise RuntimeError('Found 0 images, please check the data set')
self.mean_std = ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
def _eval_get_item(self, img, mask, scales, flip_bool):
return_imgs = []
for flip in range(int(flip_bool) + 1):
imgs = []
if flip:
img = img.transpose(Image.FLIP_LEFT_RIGHT)
for scale in scales:
w, h = img.size
target_w, target_h = int(w * scale), int(h * scale)
resize_img = img.resize((target_w, target_h))
tensor_img = transforms.ToTensor()(resize_img)
final_tensor = transforms.Normalize(*self.mean_std)(tensor_img)
imgs.append(final_tensor)
return_imgs.append(imgs)
return return_imgs, mask
def __getitem__(self, index):
img_path, mask_path = self.imgs[index]
img, mask = Image.open(img_path).convert('RGB'), m.imread(mask_path)
img_name = os.path.splitext(os.path.basename(img_path))[0]
while (img.size[1], img.size[0]) != mask[:,:,0].shape:
print("Error!!", img.size, mask[:,:,0].shape, img_name)
print("Dropping ", str(index))
# index = index + 1
if index + 1 == len(self.imgs):
index = 0
else:
index += 1
img_path, mask_path = self.imgs[index]
img, mask = Image.open(img_path).convert('RGB'), m.imread(mask_path)
img_name = os.path.splitext(os.path.basename(img_path))[0]
image_size = mask[:,:,0].shape
mask_copy = np.full(image_size, ignore_label, dtype=np.uint8)
for k, v in color_to_trainid.items():
if v != 255 and v != -1:
mask_copy[(mask == np.array(k))[:,:,0] & (mask == np.array(k))[:,:,1] & (mask == np.array(k))[:,:,2]] = v
# for k, v in color_to_trainid.items():
# mask_copy[(mask == np.array(k))[:,:,0]] = v
if self.eval_mode:
return [transforms.ToTensor()(img)], self._eval_get_item(img, mask_copy,
self.eval_scales,
self.eval_flip), img_name
mask = Image.fromarray(mask_copy.astype(np.uint8))
if self.joint_transform is not None:
img, mask = self.joint_transform(img, mask)
if self.transform is not None:
img_or = self.transform(img)
if self.color_transform is not None:
img_color = self.color_transform(img)
if self.geometric_transform is not None:
img_geometric = self.geometric_transform(img)
rgb_mean_std_or = ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
rgb_mean_std_color = ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
rgb_mean_std_geometric = ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
if self.image_in:
eps = 1e-5
rgb_mean_std_or = ([torch.mean(img_or[0]), torch.mean(img_or[1]), torch.mean(img_or[2])],
[torch.std(img_or[0])+eps, torch.std(img_or[1])+eps, torch.std(img_or[2])+eps])
rgb_mean_std_color = ([torch.mean(img_color[0]), torch.mean(img_color[1]), torch.mean(img_color[2])],
[torch.std(img_color[0])+eps, torch.std(img_color[1])+eps, torch.std(img_color[2])+eps])
rgb_mean_std_geometric = ([torch.mean(img_geometric[0]), torch.mean(img_geometric[1]), torch.mean(img_geometric[2])],
[torch.std(img_geometric[0])+eps, torch.std(img_geometric[1])+eps, torch.std(img_geometric[2])+eps])
img_or = transforms.Normalize(*rgb_mean_std_or)(img_or)
img_color = transforms.Normalize(*rgb_mean_std_color)(img_color)
img_geometric = transforms.Normalize(*rgb_mean_std_geometric)(img_geometric)
return img_or, img_color, img_geometric, img_name
def __len__(self):
return len(self.imgs)