oneflow.nn.functional.binary_cross_entropy¶
-
oneflow.nn.functional.
binary_cross_entropy
(input, target, weight=None, reduction='mean')¶ The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.nn.functional.binary_cross_entropy.html.
Function that measures the Binary Cross Entropy between the target and input probabilities.
See
BCELoss
for details.- Parameters
input – Tensor of arbitrary shape as probabilities.
target – Tensor of the same shape as input with values between 0 and 1.
weight (Tensor, optional) – a manual rescaling weight if provided it’s repeated to match input tensor shape
reduction (string, optional) – Specifies the reduction to apply to the output:
'none'
|'mean'
|'sum'
.'none'
: no reduction will be applied,'mean'
: the sum of the output will be divided by the number of elements in the output,'sum'
: the output will be summed. Note:size_average
andreduce
are in the process of being deprecated, and in the meantime, specifying either of those two args will overridereduction
. Default:'mean'
Examples:
>>> import oneflow as flow >>> import oneflow.nn.functional as F >>> input = flow.randn(3, 2, requires_grad=True) >>> target = flow.rand(3, 2, requires_grad=False) >>> loss = F.binary_cross_entropy(flow.sigmoid(input), target) >>> loss.backward()