MCPcopy Create free account
hub / github.com/XLearning-SCU/2022-CVPR-DART / __init__

Method __init__

data_loader.py:48–167  ·  view source on GitHub ↗
(self, data_dir, transform=None, colorIndex=None, thermalIndex=None, noise_rate=0., noise_file='', mode='', probV=[], probI=[])

Source from the content-addressed store, hash-verified

46
47class SYSUData(data.Dataset):
48 def __init__(self, data_dir, transform=None, colorIndex=None, thermalIndex=None, noise_rate=0., noise_file='', mode='', probV=[], probI=[]):
49
50 data_dir = data_dir
51 # Load training images (path) and labels
52 train_color_image = np.load(data_dir + 'train_rgb_resized_img.npy')
53 self.train_color_label = np.load(data_dir + 'train_rgb_resized_label.npy')
54
55 train_thermal_image = np.load(data_dir + 'train_ir_resized_img.npy')
56 self.train_thermal_label = np.load(data_dir + 'train_ir_resized_label.npy')
57
58 self.mode = mode
59 self.probI = probI
60 self.probV = probV
61
62 print("train with %.1f noisy rates" % noise_rate)
63
64 if noise_rate == 0.:
65 self.rgb_cleanIdx = range(len(self.train_color_label))
66 self.rgb_noiseIdx = []
67 self.ir_cleanIdx = range(len(self.train_thermal_label))
68 self.ir_noiseIdx = []
69 self.true_train_color_label = self.train_color_label
70 self.true_train_thermal_label = self.train_thermal_label
71 else:
72 if os.path.exists((noise_file + '_rgb.npy')):
73 print("loading files and idx of noisy labels")
74 self.train_color_label = np.load((noise_file + '_rgb.npy'))
75 self.train_thermal_label = np.load((noise_file + '_ir.npy'))
76 self.rgb_noiseIdx = np.load((noise_file + '_rgb_noiseIdx.npy'))
77 self.ir_noiseIdx = np.load((noise_file + '_ir_noiseIdx.npy'))
78 self.rgb_cleanIdx = np.load((noise_file + '_rgb_cleanIdx.npy'))
79 self.ir_cleanIdx = np.load((noise_file + '_ir_cleanIdx.npy'))
80 self.true_train_color_label = np.load((noise_file + '_rgb_true.npy'))
81 self.true_train_thermal_label = np.load((noise_file + '_ir_true.npy'))
82
83 else: # inject noise
84 for j in [0, 1]:
85 if j == 0:
86 ids = self.train_color_label[:]
87 self.true_train_color_label = ids.copy()
88 else:
89 ids = self.train_thermal_label[:]
90 self.true_train_thermal_label = ids.copy()
91 tmp_list = ids.copy()
92 unique_id = np.unique(ids)
93 noise_idx = (random.sample(range(len(ids)), int(np.ceil(noise_rate * len(ids)))))
94 noise_idx.sort()
95 clean_idx = list(set(range(len(ids))).difference(set(noise_idx)))
96
97 random.seed()
98 for i in noise_idx:
99 tmp = random.choice(unique_id)
100 while ids[i] == tmp:
101 tmp = random.choice(unique_id)
102 ids[i] = tmp
103
104 if j == 0:
105 self.train_color_label = ids.copy()

Callers

nothing calls this directly

Calls 3

ChannelAdapGrayClass · 0.90
ChannelExchangeClass · 0.85

Tested by

no test coverage detected