It depends a bit on how you would like to implement the binary segmentation.
For the usual use case, you would define a single output channel so that your output would have the shape [batch_size, 1, height ,width], while the target would have the same shape and contain values in the range [0, 1].
If your model is returning logits (no activation at the end of your model), you could use nn.BCEWithLogitsLoss to calculate the loss.
To do so, you would directly pass the model output as well as the targets to this criterion.
To calculate the accuracy, you could apply a threshold (default would be 0.0 for logits) to get the predictions and compare it with the target, if your target contains only ones and zeros.
However, if your target also contains values between 0 and 1, I’m not sure how the accuracy calculation would look like and you could probably apply a threshold of 0.5 on the target, but it depends how you are interpreting the target for this use case.
On the other hand, you could treat the binary segmentation as a multi-class segmentation use case with 2 classes.
For this approach your model would return output logits in the shape [batch_size, 2, height, width], the target would have the shape [batch_size, height, width] and contain the class indices [0, 1] (note the missing channel dimension).
nn.CrossEntropyLoss would be the criterion for this approach.
To calculate the accuracy, you would create the predictions via: preds = torch.argmax(output, 1) and compare it to the target.
Let me know, if you need more information.