Would it be possible to give more punishment to false negative mistakes?

hefan: <p>I’ m doing a multi-label classification problem of 15 classes. The net I’ m using is a Resnet50 with the last layer’s output to be 11. The loss function is BCEWithLogitsLoss.</p>
<p>I have around 12000 labeled pictures. However, the label matrix is sparse. That is to say for every picture, maybe only 1 to 2 classes will be active. Also there are a few pictures labeled all zeros.</p>
<p>First when I trained, the net tended to give me all zero result, which seems to be a local minimum.</p>
<p>Then I drop these all zero samples and use pos_weight parameters in the BCEloss to balance different classes. But the net still tends to give me the same result. (all zero predictions)</p>
<p>I wonder if there’s any method to give false negative mistakes more punishment which may help the net to predict more positive result.</p>
<p>Thanks a lot!</p>

KFrank: <p>Hi Hefan!</p>
<aside class="quote no-group" data-username="hefan" data-post="1" data-topic="98504" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/h/d9b06d/48.png" class="avatar"> hefan:</div>
<blockquote>
<p>I’ m doing a multi-label classification problem of 15 classes. The net I’ m using is a Resnet50 with the last layer’s output to be 11.</p>
</blockquote>
</aside>
<p>This seems odd.  For a 15-class classifier, I would expect your last<br>
layer to produce 15 values (not 11).</p>
<aside class="quote no-group">
<blockquote>
<p>The loss function is BCEWithLogitsLoss.</p>
</blockquote>
</aside>
<p>In this case I would expect the output of your model (the <code>input</code> to<br>
<code>BCEWithLogitsLoss</code>) to have shape <code>[nBatch, nClass = 15]</code>, and<br>
your labels (the <code>target</code>) to have the same shape.  The output of<br>
your model should be <em>logits,</em> that is, the output of the last <code>Linear</code><br>
layer of your network, <em>not</em> passed through any non-linear activation<br>
function.  Your <code>target</code> values will typically be <code>0</code> or <code>1</code> (although they<br>
could be probabilities that range from <code>0.0</code> to <code>1.0</code>).</p>
<aside class="quote no-group">
<blockquote>
<p>use pos_weight parameters in the BCEloss to balance different classes. But the net still tends to give me the same result. (all zero predictions)</p>
<p>I wonder if there’s any method to give false negative mistakes more punishment which may help the net to predict more positive result.</p>
</blockquote>
</aside>
<p>Training with <code>pos_weight</code> (when greater than 1.0) should, indeed,<br>
cause your trained network to produce more positive predictions.  If<br>
you make <code>pos_weight</code> large enough I would expect your network to<br>
be able to make positive predictions (but, of course, possibly <em>false</em><br>
positive predictions).</p>
<p>Can you successfully overfit your network by training it on a small<br>
subset of you training set so that it produces (nearly) perfect results<br>
on that subset, and therefore produces positive predictions?</p>
<p>Best.</p>
<p>K. Frank</p>