Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAELoss may be not averaged along batch dimension #28

Open
MiZhenxing opened this issue Jan 24, 2021 · 0 comments
Open

MAELoss may be not averaged along batch dimension #28

MiZhenxing opened this issue Jan 24, 2021 · 0 comments

Comments

@MiZhenxing
Copy link

MiZhenxing commented Jan 24, 2021

Hi, thank you for your excellent work. I have a question about MAELoss.

class MAELoss(nn.Module):
def forward(self, pred_depth_image, gt_depth_image, depth_interval):
"""non zero mean absolute loss for one batch"""
# shape = list(pred_depth_image)
depth_interval = depth_interval.view(-1)
mask_valid = (~torch.eq(gt_depth_image, 0.0)).type(torch.float)
denom = torch.sum(mask_valid, dim=(1, 2, 3)) + 1e-7
masked_abs_error = mask_valid * torch.abs(pred_depth_image - gt_depth_image)
masked_mae = torch.sum(masked_abs_error, dim=(1, 2, 3))
masked_mae = torch.sum((masked_mae / depth_interval) / denom)
return masked_mae

As above codes show, the Line 179 takes the sum of the average loss of each depthmap, so the resulting loss is not the average loss but the sum loss of each depthmap in one batch. I would like to ask if this would affect the training of the network, especially when the batch_size changes. Or this code is written for a purpose I don't know? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant