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

BerHuber implementation #28

Open
jrodriguezpuigvert opened this issue Jun 10, 2020 · 0 comments
Open

BerHuber implementation #28

jrodriguezpuigvert opened this issue Jun 10, 2020 · 0 comments

Comments

@jrodriguezpuigvert
Copy link

jrodriguezpuigvert commented Jun 10, 2020

Hi, thank you for your contribution. Following the BerHuber loss that u implemented, I am not sure if that is the correct implementation. I would suggest something like this:

class berHuLoss(nn.Module):
def init(self):
super(berHuLoss, self).init()

def forward(self, pred, target):
    assert pred.dim() == target.dim(), "inconsistent dimensions"
    valid_mask = (target > 0).detach()
    x_abs = (pred - target).abs()
    x_abs = x_abs[valid_mask]
    c = 0.2 * torch.max(x_abs)
    loss = torch.where(x_abs > c, (x_abs ** 2 + c ** 2) / (2 * c), x_abs).mean()
    return loss

what do u think?

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