Reputation: 302
I'm trying to train my pytorch NN module with torch.nn.BCELoss
.
My code was already running, but some changes that I can't revert are now throwing me the following error
RuntimeError: all elements of input should be between 0 and 1
. This happens when calling the loss function. However, all the elements of both inputs (the prediction and the ground truth) are between 0 and 1, as they're output from a Sigmoid!
I checked it by iterating over the tensors. Both tensors are also of the same shape and type (<torch.Tensor>
) and size (torch.Size([24375])
).
I tried exchanging the BCELoss for BCEWithLogitsLoss and omitting the output sigmoid. However, that is returning nan
results for me at the moment.
If it's relevant, I'm currently working on CPU and not on cuda.
Thanks for any help.
Upvotes: 1
Views: 1954
Reputation: 96
There are possibly two main problems with this error.
The first reason is highly probable. If your input variables have NaN in them, then it's highly probable that you will have NaN as output from your network.
Upvotes: 2