This error is usually raised, when you try to pass a spatial model output to a non-spatial target.
Have a look at this small code to reproduce the issue:
# Reproduced error
N, nb_classes, H, W = 1, 10, 24, 24
data = torch.randn(N, nb_classes, H, W, requires_grad=True)
target = torch.randint(0, nb_classes, (N,))

criterion = nn.CrossEntropyLoss()
loss = criterion(data, target) 

# Fixed by spatial target
target = torch.randint(0, nb_classes, (N, H, W))
loss = criterion(data, target)

The error is fixed once you provide a spatial target as [N, H, W].