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

when CrossEntropyLoss loss=nan #24

Closed
JonesonZheng opened this issue Mar 29, 2018 · 2 comments
Closed

when CrossEntropyLoss loss=nan #24

JonesonZheng opened this issue Mar 29, 2018 · 2 comments

Comments

@JonesonZheng
Copy link

JonesonZheng commented Mar 29, 2018

when I use

    loss = nn.CrossEntropyLoss()(output, target) 

replace the code in AngleLoss

    logpt = F.log_softmax(output)
    logpt = logpt.gather(1,target)
    logpt = logpt.view(-1)
    pt = Variable(logpt.data.exp())
    loss = -1 * (1-pt)**self.gamma * logpt
    loss = loss.mean()

I got loss=nan

I think theoretically logpt = F.log_softmax(output) here should be logpt = F.log_softmax(output,1) which is just the same as CrossEntropyLoss, but you implement is logpt = F.log_softmax(output,0)
Would you help explain it?

@clcarwin
Copy link
Owner

You can try to compare the code in focal_loss_pytorch.

@suanrong
Copy link

suanrong commented Jul 15, 2019

@JonesonZheng

I think you are right. It should be logpt = F.log_softmax(output,1)

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