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

About sigmoid focal loss cpu. #89

Open
aa1234241 opened this issue Feb 18, 2021 · 0 comments
Open

About sigmoid focal loss cpu. #89

aa1234241 opened this issue Feb 18, 2021 · 0 comments

Comments

@aa1234241
Copy link

aa1234241 commented Feb 18, 2021

Hi,
Thanks for your excellent work! One simple question here. When I read the code, I found that the focal loss code:
def sigmoid_focal_loss_cpu(logits, targets, gamma, alpha): num_classes = logits.shape[1] gamma = gamma alpha = alpha dtype = targets.dtype device = targets.device class_range = torch.arange(1, num_classes+1, dtype=dtype, device=device).unsqueeze(0) t = targets.unsqueeze(1) p = torch.sigmoid(logits) term1 = (1 - p) ** gamma * torch.log(p) term2 = p ** gamma * torch.log(1 - p) return -(t == class_range).float() * term1 * alpha - ((t != class_range) * (t >= 0)).float() * term2 * (1 - alpha)
You name it as sigmoid_focal_loss_cpu.
I am a little bit confused since this code can be run on GPU (if the input tensor device is GPU). Am I right?
Many Thanks!

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