I am having a binary classification task.
def set_parameter_requires_grad(model, feature_extracting):
for param in model.parameters():
param.requires_grad = False
model = models.resnet18(pretrained=True)
model.fc = nn.Sequential(nn.Linear(in_features=512, out_features=1, bias=True))
loss vs epochs curve(orange is validation loss)
But when I get the predictions, all the outputs are near 0.5 (which is like the model was not trained at all)
Since the loss function used was nn.BCEWithLogitsLoss(), I added an explicit sigmoid while generating the predictions.
The way I generate the predictions
As an aside, if you train with BCEWithLogitsLoss, you will be training
your model to produce logits. A model making “neutral” predictions
will produce logits near 0.0 (that correspond to probabilities near 0.5).
You haven’t given us much concrete information about your loss function
and predictions, but, making simple assumptions, your results don’t add
The graph you posted shows your loss function falling below 0.1.
A neutral prediction (a probability of 0.5 with BCELoss or a logit of 0.0 with BCEWithLogitsLoss) will give a loss of log (2), regardless
of the target value.