Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

BCEWithLogitsLossFlat and BCEWithLogitsLoss #582

Open
kfkelvinng opened this issue May 17, 2023 · 0 comments
Open

BCEWithLogitsLossFlat and BCEWithLogitsLoss #582

kfkelvinng opened this issue May 17, 2023 · 0 comments

Comments

@kfkelvinng
Copy link

kfkelvinng commented May 17, 2023

I tried to understand the difference, but they are almost identical in term of behaviour.
In the documentation https://docs.fast.ai/losses.html#bcewithlogitslossflat, nn.BCEWithLogitsLoss suppose to fail but it doesn't.

tst = BCEWithLogitsLossFlat()
output = torch.randn(32, 5, 10)
target = torch.randn(32, 5, 10)
#nn.BCEWithLogitsLoss would fail with those two tensors, but not our flattened version.
_ = tst(output, target)
test_fail(lambda x: nn.BCEWithLogitsLoss()(output,target))

The correct test should be:

test_fail(lambda: nn.BCEWithLogitsLoss()(output,target))

instead of

test_fail(lambda x: nn.BCEWithLogitsLoss()(output,target))

In contrast to https://docs.fast.ai/losses.html#crossentropylossflat, the nn.CrossEntropyLoss fail but the test is misleading.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant