As suggested I changed my output_channels to 1 but now I am getting the following error:

RuntimeError: Assertion `cur_target >= 0 && cur_target < n_classes’ failed.

Searching the error suggests that my labels are not zero indexed. I guess that is the reason it was working with output_channels=2 and is failing when the output channels is the same as that of the target.
How would I zero index my target tensor to satisfy this condition?