For a multi-class segmentation use case, you should use nn.CrossEntropyLoss where the model output should be a FloatTensor in the shape [batch_size, nb_classes, height, width] and the target a LongTensor in the shape [batch_size, height, width] containing the class indices in the range [0, nb_classes-1].
If you are dealing with a binary or multi-label segmentation, you could use nn.BCEWithLogitsLoss, which would expect a target as a FloatTensor in the same shape as the model output containing values in [0, 1].