Solved by ptrblck in post #2 
              
              
                You should use nn.CrossEntropyLoss and can have a look at the docs to see how the loss formula is implemented. 
I would recommend to skip the spatial dimensions for now and just take a look at the standard multi-class classification use case, where the output has the shape [batch_size, nb_classes] a…