Hi Luca!



 Luca_Viano:

element wise binary classification using the BCEloss.
its last activation is an element wise Sigmoid.


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


my model predicts for all pixels probabilities that are lower than 0.5 so all the elements equal to 1 are wrongly classified.
I think that this is mainly due to the fact that the 1s are rare in the tensor.


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 reweight the rare values would be
approx_number_of_1_pixels / approx_number_of_0_pixels.
(The value for pos_weight does not need to be especially precise.)
Note:  You don’t need to use 0.5 as the threshold to convert predicted
probabilities (or 0.0 to threshold logits) to 0/1 values.  You can lower
the threshold to predict more 1s (but using pos_weight is likely to be
the better approach).
Best.
K. Frank