Ravindra BagaleCourses & study guides मराठी Track your progress

45. Your First Neural Network in PyTorch

45.4 Predict with Sigmoid

Why. After training, convert logits to probabilities and decisions.

What. torch.sigmoid(logits) → probability. Threshold 0.5 → class 0/1 for a demo.

How.

Predict

  1. Set model.eval().
  2. Use torch.no_grad() so you do not build a graph.
  3. Print probs and hard labels.
model.eval()
with torch.no_grad():
 logits = model(X)
 probs = torch.sigmoid(logits)
 preds = (probs >= 0.5).float()
print("probs:\n", probs.round(decimals=3))
print("preds:\n", preds)

Ravindra Bagale's Tip

eval + no_grad = inference mode. Training mode vegla; habit solid theva.