@melste  what I gave as code was to be able to calculate things like accuracy, precision and other … Otherwise for the calculation of the loss, it remains :

either you remove the Sigmoid layer at the output of the model : advised, because more stable

loss_fn = nn.BCEWithLogitsLoss()

logits = model(...your inputs...)

loss = loss_fn(logits, y)

Then you can apply the sigmoid to the logits output as I mentioned in my post above, to know if your model has predicted 0 or 1.
prediction = (logits >= 0.).int()
# Or if you prefer to use the sigmoid (x > 0 <====> 1 / (1+e-x) > 0.5 )
probability  = torch.sigmoid(logits)
prediction = probability.round().int() # = (probability >= 0.5).int()


or you keep this sigmoid layer

loss_fn = nn.BCELoss()

probability = model(...your inputs...)

loss = loss_fn(probability, y)

In this case your model returns directly a probability (between [0,1]), that you can also compare to 0.5 to know if your model has predicted 0 or 1.
prediction = probability.round().int() # = (probability >= 0.5).int()