Patrice:

I am using a customized loss function consisting of the combination of cross_entropy loss and dice loss.


Could you post the custom loss and explain what your model outputs?
Since you are using nn.CrossEntropyLoss, I assume your model returns an output in the shape [batch_size, 2, height, width]? If that’s the case, you should not apply any threshold, but get the predicted classes via preds = torch.argmax(output, 1).



 Patrice:

In this case, how should the threshold be applied? Please, could you provide a sample code?


If your model returns logits of the shape [batch_size, 1, height, width], you could get the predictions via: preds = output > 0.0. However, see the comment before, as I’m skeptical what your model returns.