Solved by KFrank in post #2 
              
              
                Hi John! 

I would recommend that you use BCEWithLogitsLoss's weight 
argument: 
    mean_weighted_loss = torch.nn.BCEWithLogitsLoss (weight = pix_map) (pred, target)

As a further comment:  You can certainly write your own version of 
BCEWithLogitsLoss, but if you do, you should, for reasons of 
nu…