Hi Rafael!



 auyer:

I am running a Transfer Learning scenario with a ResNet model. The original work was a classifier with hundreds of classes, and it used the CrossEntropyLoss function nn.CrossEntropyLoss().
A thread  here suggest BCELoss, but there is BCEWithLogitsLoss that also seems fit.


For a binary classification problem, BCEWithLogitsLoss
should be your go-to loss function.  (You would only want to
use BCELoss if your network naturally emits probabilities,
which it almost certainly doesn’t.)


In a confusion matrix, I want to optimize for the least amount of False Positives, even if it hurts my True Positive score.
What (of all) loss functions should I use ? And why ?


Consider carefully the trade-off that you are implying here.  As
an extreme, you could simply classify everything as “negative”.
You now achieve the “least amount of False Positives” (none
at all), but, of course your True Positive score is also really
bad, that is, zero.
So I assume your real trade-off is that you are willing to reduce
your True Positives some, but not too much,  if you can get a
substantial reduction in your False Positives.
A sensible approach to achieve this would be to weight your
“negative” samples more heavily than your “positive” samples.
BCEWithLogitsLoss has a weight argument for this purpose.
The relative weight between your “negative” and “positive” samples
will determine how much you train your network to reduce your
False Positives at the cost of reducing your True Positives.
Good luck.
K. Frank