Spaces:
Running
on
A10G
Running
on
A10G
# ------------------------------------------------------------------------------ | |
# The code is from GLPDepth (https://github.com/vinvino02/GLPDepth). | |
# For non-commercial purpose only (research, evaluation etc). | |
# ------------------------------------------------------------------------------ | |
import torch | |
import torch.nn as nn | |
class SiLogLoss(nn.Module): | |
def __init__(self, lambd=0.5): | |
super().__init__() | |
self.lambd = lambd | |
def forward(self, pred, target): | |
valid_mask = (target > 0).detach() | |
diff_log = torch.log(target[valid_mask]) - torch.log(pred[valid_mask]) | |
loss = torch.sqrt(torch.pow(diff_log, 2).mean() - | |
self.lambd * torch.pow(diff_log.mean(), 2)) | |
return loss | |