I assume the semantic segmentation is a multi-class segmentation, i.e. each pixel belongs to exactly one class.
If so, this should be possible using these shapes
N, nb_classes, H, W = 2, 3, 4, 4
output = torch.randn(N, nb_classes, H, W, requires_grad=True)
target = torch.randint(0, nb_classes, (N, H, W))

loss = criterion(output, target)

Note that the nb_classes dimension is missing in the target as described in the docs, so make sure to pass these shapes to your criterion.
nn.BCEWithLogitsLoss is most likely not, what you are looking for.