For a binary segmentation use case, you could simply use nn.BCEWithLogitsLoss, which would accept the shapes you are currently providing.
nn.CrossEntropyLoss is used for a multi-class segmentation use case. It can also be used for a binary classification, but would require your output to have the shape [batch_size, 2, height, width] and the target to have the shape [batch_size, height, width] containing the class indices in the range [0, 1].