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

why modulator? #9

Open
lai199508 opened this issue Apr 14, 2020 · 2 comments
Open

why modulator? #9

lai199508 opened this issue Apr 14, 2020 · 2 comments

Comments

@lai199508
Copy link

Hi, i'm interested in your work! Now i have problem, why your implement code of focal loss use "modulator = torch.exp(-gamma * labels * logits - gamma * torch.log(1 + torch.exp(-1.0 * logits)))" ?

@xiaoyu825
Copy link

it's just a transfer of the formula,but "labels" should not show in the code.i think it is modulator = torch.exp(-gamma * logits - gamma * torch.log(1 + torch.exp(-1.0 * logits)))

@wutong16
Copy link

wutong16 commented May 12, 2020

it's the formula of focal loss, and "labels" should be reserved.
image
notice that y' = 1 / (1 + torch.exp(-1.0 * logits)), and both logits and labels are matrixs.

for where labels is 0, modulator = (1 / (1 + torch.exp(-1.0 * logits))) ** gamma,
and for where labels is 1, modulator = (torch.exp(-1.0 * logits) / (1 + torch.exp(-1.0 * logits)) ** gamma = (1 / (1 + torch.exp(logits)) ** gamma

matching the formula well.

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

3 participants