The class dimension should be in dim1 in your model output, so this code should work:
criterion = nn.CrossEntropyLoss()
input = torch.randn((20, 2, 30, 30), requires_grad=True)
target = torch.empty((20,30,30), dtype=torch.long).random_(2)
output = criterion(input, target)

I’m not sure, if the TF code returns an unreduced loss, but if so you could set reduction='none' in your criterion instantiation.