You shouldn’t simply reshape your target to a spatial shape, if you have scalar values.
Instead of changing the target, you should change your model architecture to return logits in the right shape.
Based on the provided target shape (multi-class classification), your model should return logits in the shape [batch_size, nb_classes].