How to customize threshold PyTorch
I have trained ResNet50 for binary image classification.
I want to descrease FalseNegatives by reducing threshold value.
How can I do that?

To decrease the number of false negatives (FN) i.e. increase the recall (since recall = TP / (TP + FN)) you should increase the positive weight (the weight of the occurrence of that class) above 1. For example nn.BCEWithLogitsLoss allows you to provide the pos_weight option:

pos_weight &gt; 1 increases the recall, pos_weight &lt; 1 increases the precision.
For example, if a dataset contains 100 positive and 300 negative examples of a single class, then pos_weight for the class should be equal to 300/100 = 3. The loss would act as if the dataset contains 3*100 = 300 positive examples.

As a side note, the explicit expression for the binary cross entropy with logits (where &quot;with logits&quot; should rather be understood as &quot;from logits&quot;) is:
&gt;&gt;&gt; z = torch.sigmoid(q)
&gt;&gt;&gt; loss = -(w_p*p*torch.log(z) + (1-p)*torch.log(1-z))

Above q are the raw logit values while w_p is the weight of the positive instance.
