Solved by RoySadaka in post #2 
              
              
                I think the issue is that you have 2 means 

The first one is that you have the sum and then divide by the size (but you should use target.numel() instead of target.size(1))
Second is when you use torch.mean

So 2 options: 
Here is your code with torch.mean 
def bce_loss(pred, target):
    pred=F.si…