BCELoss — PyTorch 1.10.1 documentation
pytorch.org › docs › stableBCELoss. class torch.nn.BCELoss(weight=None, size_average=None, reduce=None, reduction='mean') [source] Creates a criterion that measures the Binary Cross Entropy between the target and the input probabilities: The unreduced (i.e. with reduction set to 'none') loss can be described as:
How to use Cross Entropy loss in pytorch for binary prediction?
datascience.stackexchange.com › questions › 37128Aug 18, 2018 · PyTorch has BCELoss which stands for Binary Cross Entropy Loss. Please check out original documentation here. Here is a quick example: m = nn.Sigmoid () # initialize sigmoid layer loss = nn.BCELoss () # initialize loss function input = torch.randn (3, requires_grad=True) # give some random input target = torch.empty (3).random_ (2) # create some ground truth values output = loss (m (input), target) # forward pass output.backward () # backward pass.