Solved by KFrank in post #2 
              
              
                Hi Luca! 

As an aside, you will have better numerical stability if you use 
BCEWithLogitsLoss and remove the final Sigmoid layer. 

Consider using the pos_weight argument passed to the constructor 
of BCEWithLogitsLoss to compensate for the rarity of “1” pixels. 
A typical value for pos_weight to r…