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

Questions on the Focal Loss computation in the SSD Chapter #117

Open
aurotripathy opened this issue Jan 2, 2021 · 1 comment
Open

Questions on the Focal Loss computation in the SSD Chapter #117

aurotripathy opened this issue Jan 2, 2021 · 1 comment

Comments

@aurotripathy
Copy link

Two questions

  1. alpha_t is unused below.
  2. should we use the following to derive the BCECrossEntropyLoss:

pt = torch.log(p) * target.float() + torch.log(1.0 - p) * (1 - target).float()

class FocalLoss(nn.Module):
    def __init__(self, alpha=0.25, gamma=2, device="cuda:0", eps=1e-10):
        super().__init__()
        self.alpha = alpha
        self.gamma = gamma
        self.device = device
        self.eps = eps

    def forward(self, input, target):
        p = torch.sigmoid(input)
        pt = p * target.float() + (1.0 - p) * (1 - target).float()
        alpha_t = (1.0 - self.alpha) * target.float() + self.alpha * (1 - target).float()
        loss = - 1.0 * torch.pow((1 - pt), self.gamma) * torch.log(pt + self.eps)
        return loss.sum()
@aurotripathy
Copy link
Author

Maintainers, kindly respond (or provide hint)

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