Hello phdproblems!



 phdproblems:




 KFrank:

(You could recast your problem
as a two-class (foreground / background) multiclass classification
problem and use CrossEntropyLoss , but I wouldn’t recommend it.)


Can you please mention why you would not recommend this, I though BCE is just CE but for a binary problem, is it not advised to use CE for binary problems?


BCE takes a single number per sample for its prediction – the
probability of the sample being in class “1”.
Multiclass CE takes, for N classes, N numbers for its prediction.
These are the probabilities of the sample being in each of the
N classes.  (Pytorch’s CrossEntropyLoss has a softmax
implicitly built in, so it takes logits, rather than probabilities.)
So if you use multiclass CE for a binary (two-class) problem,
you will now have to pass two numbers to it instead of one.
(If these are official probabilities, they will be redundant, in
that they will sum to 1.)  So your network will have to have
two (redundant) outputs instead of one.  Hardly a big deal,
but it would presumably make your network ever so slightly
less efficient.
If you do everything correctly, you will be doing exactly the
same problem and will get exactly the same result (up to
some round-off error), but it just seems cleaner to me to
use BCE for the binary problem.
Best.
K. Frank