Yes, you could use a sigmoid to get the probabilities and calculate the accuracy using a threshold. Alternatively you could also use a threshold directly on the logits (no sigmoid), but a threshold in the range [0, 1] might be easier and more intuitive to use.
If you put the sigmoid directly into the model, nn.BCELoss will apply torch.log internally, while passing logits to nn.BCEWithLogitsLoss will use the log-sum-exp trick as seen in these lines of code and will thus yield more numerical stability.


I don’t have a strong opinion on it and feel free to chime in your opinion on what’s the less confusing approach.  Generally “mathematical” functions should go into the torch namespace, while NN-specific methods should stay in the nn.functional namespace as described here. torch.nn.functional.sigmoid should still work I think.