nn.CrossEntropyLoss can be applied if you permute the output to match the expected shapes:
  
    
    
    Multi-class cross entropy loss and softmax in pytorch vision
  
  
    nn.CrossEntropyLoss expects raw logits in the shape [batch_size, nb_classes, *] so you should not apply a softmax activation on the model output. The class dimension should be in dim1 in the model output.
  


I don’t know, how TF is applying a binary cross-entropy with a softmax activation function, as I assume internally this formula 16 would be used, which involves the sigmoid.