rajibmon:

because I have a pixel-wise two-class classification problem: background vs. foreground. Therefore the number of output channels and the number of target channels equals 1, in my case.


Your output should have the shape [batch_size, nb_classes=2, height, width] for a two-class classification with CrossEntropyLoss.
Also, use F.log_softmax(logit, dim=1) to apply the log_softmax in the class dimension.