How to use BCELossWithLogits for foreground,background(binary) semantic classifaction

Hi everyone, I am trying to use the BCE logit loss function for binary semantic segmentation.Output of my network is [batch size,2,h,w] and the label is [batchsize,h,w]. I have read all the forums regarding this problem my doubt is not clarified. How to feed this input and target to the BCElogitloss without doing any one-hot encoding.
thanks in advance

You just need a GT whose shape matches the output.
You should make your network to predict a single channel, encoding 1 as foreground and 0 as background.