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

CrossEntropyLoss reduction write error #205

Open
AutumnZ-94 opened this issue Aug 3, 2021 · 1 comment
Open

CrossEntropyLoss reduction write error #205

AutumnZ-94 opened this issue Aug 3, 2021 · 1 comment

Comments

@AutumnZ-94
Copy link

AutumnZ-94 commented Aug 3, 2021

should

loss = (- targets * log_probs).mean(0).sum() in https://github.com/michuanhaohao/reid-strong-baseline/blob/master/layers/triplet_loss.py#L146

be supposed to loss = (- targets * log_probs).sum(1).mean()?

@AutumnZ-94 AutumnZ-94 changed the title CrossEntropyLoss reduction bug CrossEntropyLoss reduction write error Aug 3, 2021
@SuperbTUM
Copy link

@AutumnZ-94 Try this. They should be the same

x = torch.randn(32, 64)

y1 = x.mean(0).sum()
y2 = x.sum(1).mean()

assert torch.allclose(y1, y2)

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