For a multi-class segmentation you would most likely use nn.CrossEntropyLoss, which expects the target masks to have the shape [batch_size, height, width] and contain the class indices in the range [0, nb_classes-1].
If your current targets are grayscale images with discrete gray values for each class, you could map these values to class indices e.g. by using a lookup table.