Could you post the code snippet which throws this error?
Are you passing the model output as float and targets as long to nn.CrossEntropyLoss?



 noornk:

And when my output is [batch_size, 2, h, w], take for example these two cells: [0, 0, 10, 10] and [0, 1, 10, 10]. Shouldn’t the values complement each other? because the cell is in either class?


Since they represent logits, you won’t see any pattern there.
However, you could apply a softmax on dim1 and see the corresponding probabilities in each channel for the sake of debugging.