Solved by KFrank in post #2 
              
              
                Hi David! 

First, as an aside:  I haven’t looked closely at your WeightedBCE code, but I 
don’t see anything mathematically wrong with it.  However, the for-loop over 
label will slow things down in comparison with pytorch’s built-in BCELoss 
(and the preferred BCEWithLogitsLoss). 

Pytorch’s built…