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

Chapter 6: TypeError in Binary Cross Entropy calculation using both nn.BCEWithLogitsLoss() and F.binary_cross_entropy_with_logits() #627

Open
abidhasan03 opened this issue Oct 26, 2023 · 1 comment

Comments

@abidhasan03
Copy link

In the Chapter 6 notebook: 06_multicat.ipynb,
The binary cross entropy calculation using either the nn module or F function gives "TypeError"

Executing this cell,

loss_func = nn.BCEWithLogitsLoss()     
loss = loss_func(activs, y)     
loss

Gives,
TypeError: no implementation found for 'torch.nn.functional.binary_cross_entropy_with_logits' on types that implement __torch_function__: [<class 'fastai.torch_core.TensorImage'>, <class 'fastai.torch_core.TensorMultiCategory'>]

Furthermore, trying to calculate the same loss using function seems to run into the same problem too.

loss = F.binary_cross_entropy_with_logits(activs, y)
loss

TypeError: no implementation found for 'torch.nn.functional.binary_cross_entropy_with_logits' on types that implement __torch_function__: [<class 'fastai.torch_core.TensorImage'>, <class 'fastai.torch_core.TensorMultiCategory'>]

The issue persisted in both CPU and GPU runtime.

@Udayk02
Copy link

Udayk02 commented Dec 8, 2023

The issue says that the F.binary_cross_entropy_with_logits does not work on TensorImage and also it will not work on TensorMask. So, you need to change those to torch tensors to make them work. You can wrap them with TensorBase() and you are good to go.

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