fix rgb dimension bug

This commit is contained in:
Justin committed 2023-02-03 23:14:27 +00:00
1 parent 4157e21e28
commit 177b86d490
1 file changed
+10 -8
+10 -8
View File
@@ -303,13 +303,12 @@ def depth_loss(
raise NotImplementedError("Provided depth loss type not implemented.")
def robust_rgb_loss(rgb_outputs,rgb_gt,patch_size=16):
out_patches = rgb_outputs.view(-1,1,patch_size,patch_size)
gt_patches = rgb_gt.view(-1,1,patch_size,patch_size)
def robust_rgb_loss(rgb_gt,rgb_outputs,patch_size=16):
out_patches = rgb_outputs.view(-1,1,patch_size,patch_size,3)
gt_patches = rgb_gt.view(-1,1,patch_size,patch_size,3)
device = rgb_outputs.device
batch_size = out_patches.shape[0]
residuals = (out_patches - gt_patches)**2
residuals = torch.mean((out_patches - gt_patches)**2,dim=-1)
with torch.no_grad():
med_residual = torch.median(residuals)
#equation 8
@@ -317,8 +316,11 @@ def robust_rgb_loss(rgb_outputs,rgb_gt,patch_size=16):
#equation 9
blurred_w = (torch.nn.functional.conv2d(weight,(1/9.)*torch.ones((1,1,3,3),device=device),padding='same')>0.5).float()
expected_w = torch.mean(torch.mean(blurred_w,dim=-1),dim=-1)
#equation 10
weight_r8 = (expected_w > 0.6).float()
w_8x8 = weight_r8[...,None] * torch.ones((batch_size,8,8),device=device)
final_w = torch.zeros((batch_size,16,16),device=device)
final_w[:,4:12,4:12] = w_8x8
return torch.mean(residuals*final_w)
final_w = torch.zeros((batch_size,patch_size,patch_size),device=device)
final_w[:,
(patch_size//2-patch_size//4):(patch_size//2+patch_size//4),
(patch_size//2-patch_size//4):(patch_size//2+patch_size//4)] = w_8x8
return torch.mean(residuals.squeeze()*final_w)