![]() |
VOOZH | about |
In this article, we are going to see how to Measure the Binary Cross Entropy between the target and the input probabilities in PyTorch using Python. We can measure this by using the BCELoss() method of torch.nn module.
The BCELoss() method measures the Binary Cross Entropy between the target and the input probabilities by creating a criterion. This method is used for measuring the error of reconstruction, an auto-encoder is a good example of it. The input and target must be tensors of any number of dimensions and the target should be between 0 to 1. before moving further let's see the syntax of the given method.
Syntax: torch.nn.BCELoss()
In this example, we measure the Binary Cross Entropy between the target and the input probabilities of the 1D tensor.
Output:
In this example, we measure the Binary Cross Entropy between the target and the input probabilities of the 2D tensor.
Output: