Firstly, nn.CrossEntropyLoss() is mostly used when you need multple predictions.
Since you have just one output neuron, you must use nn.Sigmoid() followed by nn.BCELoss() or simply nn.BCELossWithLogits().
Just need a clarification,
You have single output neuron.
Your target spans between 0 and 1.
Consider a batch-size of 7.
pred_batch will be of shape (7,1) since u have single neuron.
target shape will be (7,) with minimum value of 0 and maximum value of 1.
Right ?
How come you are able to pass these inside CrossEntropyLoss() without getting any error.?
Didn’t BCELosswithLogits() do the purpose then ?
If you were using this bce-with-logits, then torch.sigmoid() is the right way as you have posted in the question.
If you’ve used nn.CrossEntropyLoss(), then u apply Softmax(), and pick the class which has the highest value.
In your case, picking the class with highest value would always result in the same class ( zeroth class ), since you have just one neuron.