Hi Mr. Robot!



 MrRobot:

The key difference of nn.CrossEntropyLoss() and nn.BCEWithLogitsLoss() is the former uses Softmax while the latter uses multiple Sigmoid when computing loss.
…


While true, this is hardly the key difference between the two.
Let me first clear up a potential point of confusion:
“Multi-class” classification means that a given sample is in precisely
one class.  (One of your classes can be “background” or “no class”
or “unclassified” if this fits your workflow.)  (Binary classification means
that you have two classes, e.g., “yes” and “no” or “0” and “1”.)
“Multi-label” classification means that each sample can be in any
number of the specified classes, including zero.  So multi-label
classification can be understood as a series of binary classifications:
Is sample 1 in class A – yes or no?  Is sample 1 in class B – yes or no?
And so on.
You can’t use CrossEntropyLoss to do multi-label classification.
(It’s just the ticket, though, for multi-class classification.)
You can use BCEWithLogitsLoss for multi-label classification
(as well as for ordinary, single-label binary classification).
Could you clarify whether you are doing multi-class or multi-label
classification, and then follow up with any further questions you have?
Good Luck.
K. Frank