Skip to content

weighted sum in masked loss #416

@nehSgnaiL

Description

@nehSgnaiL

Hi,

Thanks for the remarkable work.

I would like to know more about the operations in defined loss. Since the mask has been normalized by mask /= torch.mean(mask), should we use the sum operation torch.sum(loss) rather than the mean operation torch.mean(loss) in returning loss?

def masked_mse_torch(preds, labels, null_val=np.nan):
labels[torch.abs(labels) < 1e-4] = 0
if np.isnan(null_val):
mask = ~torch.isnan(labels)
else:
mask = labels.ne(null_val)
mask = mask.float()
mask /= torch.mean(mask)
mask = torch.where(torch.isnan(mask), torch.zeros_like(mask), mask)
loss = torch.square(torch.sub(preds, labels))
loss = loss * mask
loss = torch.where(torch.isnan(loss), torch.zeros_like(loss), loss)
return torch.mean(loss)

I am not sure what I understand is right due to my limited knowledge. If you could respond, that would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions