If the number of classes is 27, dim1 should have this size.
.permute is a tensor method, not a numpy.array method, so you should apply it on the model output tensor before passing it to the criterion.