so loss = Variable(loss, requires_grad = True)
seems to fix the error.
I think I explained it a bit wrong. Basically it should compare the first and second channel. You compare every element in the channel and if the first channel’s number > second channel’s number then you encode a 0 for that location, otherwise change it to a 1.
This is done because my UNet produces 2 channels - probability of 0 and probability of 1 for the mask i’m creating for segmentation. So i’m using this method to convert it to one channel.
Your solution seems to find the maximum of the two. When I tried it, it didn’t encode it into 1’s and 0’s like I had. Please let me know if you have another solution, since you seem pretty knowledgable.