def criterionHis(self, input_data, target_data, mask_src, mask_tar, index): input_data = (self.de_norm(input_data) * 255).squeeze() target_data = (self.de_norm(target_data) * 255).squeeze() mask_src = mask_src.expand(1, 3, mask_src.size(2), mask_src.size(2)).squeeze() mask_tar = mask_tar.expand(1, 3, mask_tar.size(2), mask_tar.size(2)).squeeze() input_masked = input_data * mask_src target_masked = target_data * mask_tar input_match = histogram_matching(input_masked, target_masked, index) input_match = self.to_var(input_match, requires_grad=False) loss = self.criterionL1(input_masked, input_match) return loss
def criterionHis(self, input_data, target_data, mask_src, mask_tar, index): input_data = (self.de_norm(input_data) * 255) target_data = (self.de_norm(target_data) * 255) mask_src = mask_src.expand(-1, 3, mask_src.size(2), mask_src.size(3)) mask_tar = mask_tar.expand(-1, 3, mask_tar.size(2), mask_tar.size(3)) input_masked = input_data * mask_src target_masked = target_data * mask_tar # dstImg = (input_masked.data).cpu().clone() # refImg = (target_masked.data).cpu().clone() input_match = [] for (i, t, idx) in zip(input_masked, target_masked, index): input_match.append(histogram_matching(i, t, idx)) input_match = torch.stack(input_match) input_match = self.to_var(input_match, requires_grad=False) loss = self.criterionL1(input_masked, input_match) return loss