-
Hello everyone, I replaced and in the training loop: Do note that With these changes from what Daniel sir taught in the online course lecture of Pytorch in the lecture I ran the code, but the loss is not decreasing. Can Daniel sir or somebody help. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@harivan86 seems like you forgot to set the model to train mode on ur training loop. Corrected code: for epoch in range(epochs):
model.train() # Set your model (model_name) to train mode
# 1. Forward pass
y_logits = model_3(X_train).squeeze()
y_pred = torch.round(torch.sigmoid(y_logits)) # logits -> prediction probabilities -> prediction labels Can you run you code once again with above changes. |
Beta Was this translation helpful? Give feedback.
@harivan86 You were passing the rounded logit values (after applying sigmoid) to the loss function causing the loss (BCE Loss) not to decrease.
Note
Use
y_pred = torch.round(torch.sigmoid(y_logits))
to calculate accuracy. For BCELoss, as stated in the PyTorch documentation, pass the sigmoid logits only rather than the rounded sigmoid logit values.https://pytorch.org/docs/stable/generated/torch.nn.BCELoss.html
Here’s the corrected code: