torch.nn.functional.binary_cross_entropy_with_logits — PyTorch 2.7 documentation (original) (raw)

torch.nn.functional.binary_cross_entropy_with_logits(input, target, weight=None, size_average=None, reduce=None, reduction='mean', pos_weight=None)[source][source]

Calculate Binary Cross Entropy between target and input logits.

See BCEWithLogitsLoss for details.

Parameters

Return type

Tensor

Examples:

input = torch.randn(3, requires_grad=True) target = torch.empty(3).random_(2) loss = F.binary_cross_entropy_with_logits(input, target) loss.backward()