Hi James!



 James_Lee:

Can I adopt the weight for specific pixels?


The documentation is misleadingly unclear, but BCEWithLogitsLoss
(which you should use) and BCELoss (which you shouldn’t use)
do support what you call “pixel-by-pixel” weights (as do their
functional equivalents).
Let’s assume that input and target have the same shape (which
they will in any reasonable use case).  Then what is required is that
the weight argument passed into BCEWithLogitsLoss's constructor
have a shape that is broadcastable to the shape of input (and hence
to the shape of target).  After broadcasting, weight is just used to
weight each element-by-element term in the loss function on an
element-by-element basis.
(Those elements can be pixels in an image, classes in a
multi-label problem, channels, etc., or any combination thereof.
BCEWithLogitsLoss doesn’t care how you choose to interpret
them – they’re just elements of a multi-dimensional tensor.)
If weight has the same shape as input, then no broadcasting is done
(or you could say that the broadcasting is trivial), and weight will be
applied to “specific pixels” in the way that I think you’re asking for.
Best.
K. Frank