Hi John!



 John_Doe:

My implementation currently looks like this :
    unweighted_loss = target * torch.log(sig_pred) + (1 - target) * torch.log(1 - sig_pred)
    weighted_loss = -(pix_map * unweighted_loss)
    mean_weighted_loss = weighted_loss.mean()



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
numerical stability, use logsigmoid() instead of sigmoid():
    log_sig_pred = torch.nn.functional.logsigmoid (pred)
    log_sig_neg_pred = torch.nn.functional.logsigmoid (-pred)
    unweighted_loss = target * log_sig_pred + (1 - target) * log_sig_neg_pred

Best.
K. Frank