nn.BCEWithLogitsLoss is the class and nn.functional.binary_cross_entropy_with_logits is the function of the binary cross-entropy with logits loss.
They both have the same results, but are used in a different way:


criterion = torch.nn.BCEWithLogitsLoss(pos_weight=pos_weight)
Then you can do criterion(output, target)

loss = nn.functional.binary_cross_entropy_with_logits(output, target)

Using BCEWithLogitsLoss you are able to define certain parameters when creating the loss (e.g. weight ). Please look at the documentation for details. 4