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

Wrong loss function? #9

Open
mengcz13 opened this issue Jul 12, 2021 · 1 comment
Open

Wrong loss function? #9

mengcz13 opened this issue Jul 12, 2021 · 1 comment

Comments

@mengcz13
Copy link

I notice that the code uses CrossEntropyLoss for local training:

self.loss_func = nn.CrossEntropyLoss()

And it accepts the log-probabilities as input:

loss = self.loss_func(log_probs, labels)

The output of CNN networks is also logsoftmax:

return F.log_softmax(x, dim=1)

But according to the doc of PyTorch, CrossEntropyLoss already has logsoftmax inside:
https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html#torch.nn.CrossEntropyLoss

I think the loss should be calculated via NLLLoss instead if used with input after logsoftmax (https://pytorch.org/docs/stable/generated/torch.nn.NLLLoss.html#torch.nn.NLLLoss).

Or is there any reason why the code uses logsoftmax twice for calculating the loss?

@CarlBye
Copy link

CarlBye commented Oct 3, 2021

Same issue

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

2 participants