You can

use a single output unit without any activation function at the end and lass this logit to nn.BCEWithLogitsLoss. For this the targets should have the same shape as the model output and be FloatTensors. To get the predicted label you can apply torch.sigmoid and use a threshold via preds = output > threshold.
use two output units (treat the binary segmentation as a multi-class segmentation) and pass the logits to nn.CrossEntropyLoss. The target would be the LongTensor as described before. To get the predicted classes you can use preds = torch.argmax(output, dim=1).