That is compact, I’ll try it out.
What I came up was a simple one, just to get it working, one using just sum()
    n, c, h, w = predictions.size()
    nt, ct, ht, wt = labels.size()

    loss = (labels * torch.log(predictions)).sum(2).sum(2)  # for all pixels in an image
    loss = loss.sum(1)            # for all classes
    loss = -torch.mean(loss)  # for the entire batch

and the other using view().sum(), which was only different for the first line below:
    loss = (labels * torch.log(predictions)).view(n, c, -1).sum(2)  # for all pixels in an image
    loss = loss.sum(1)            # for all classes
    loss = -torch.mean(loss)  # for the entire batch