Thanks for your answer, it helped me a lot.
It worked for me with nn.BCEWithLogitsLoss, but I would like to make it work with nn.CrossEntropyLoss also.
In my problem, the goal is to make the network output look as much as the target as possible. That makes me think that my problem is not a classification but a regression problem.
So, when I try to set the dimension of the network output like [batch_size, C, height, width] (being C = number of classes), I cannot set the number of classes because I don’t have them.
How should I use the nn.CrossEntropyLoss for a regression problem?