After some digging in PyTorch documentation, I found BCEloss which is cross entropy loss for binary classification. Shouldn’t I use that instead? I can repeat my target from [B, H, W] to [B, 2, H, W] so that it matches the shape of my output.
And by using BCEloss, I will not have to remove the last layer of cross entropy loss.
I tried using cross entropy loss as you suggested but I am getting another error:
RuntimeError: copy_if failed to synchronize: device-side assert triggered