Hi @alx,
the code is perfectly fine upto optimizer.step()
Please add these steps after that line
probabilities  = torch.sigmoid(pred_batch)
pred_batch[probabilities>=0.5] = 1
pred_batch[probabilities<0.5]  = 0

This is the first case which you have asked in your question.!