class_docstr: This operator combines the sigmoid layer and the :ref:`api_nn_loss_BCELoss` layer.
  Also, we can see it as the combine of ``sigmoid_cross_entropy_with_logits``
  layer and some reduce operations.
  This measures the element-wise probability error in classification tasks
  in which each class is independent.
  This can be thought of as predicting labels for a data-point, where labels
  are not mutually exclusive. For example, a news article can be about
  politics, technology or sports at the same time or none of these.
  First this operator calculate loss function as follows:
  .. math::
         Out = -Labels * \\log(\\sigma(Logit)) - (1 - Labels) * \\log(1 - \\sigma(Logit))
  We know that :math:`\\sigma(Logit) = \\frac{1}{1 + \\e^{-Logit}}`. By substituting this we get:
  .. math::
         Out = Logit - Logit * Labels + \\log(1 + \\e^{-Logit})
  For stability and to prevent overflow of :math:`\\e^{-Logit}` when Logit < 0,
  we reformulate the loss as follows:
  .. math::
         Out = \\max(Logit, 0) - Logit * Labels + \\log(1 + \\e^{-\|Logit\|})
  Then, if ``weight`` or ``pos_weight`` is not None, this operator multiply the
  weight tensor on the loss `Out`. The ``weight`` tensor will attach different
  weight on every items in the batch. The ``pos_weight`` will attach different
  weight on the positive label of each class.
  Finally, this operator applies reduce operation on the loss.
  If :attr:`reduction` set to ``'none'``, the operator will return the original loss `Out`.
  If :attr:`reduction` set to ``'mean'``, the reduced mean loss is :math:`Out = MEAN(Out)`.
  If :attr:`reduction` set to ``'sum'``, the reduced sum loss is :math:`Out = SUM(Out)`.
  Note that the target labels ``label`` should be numbers between 0 and 1.
  Args:
      weight (Tensor | str, optional): A manual rescaling weight given to the loss of each
          batch element. If given, it has to be a 1D Tensor whose size is `[N, ]`,
          The data type is float32, float64. If type is str, it should equal to 'dynamic'.
          It will compute weight dynamically in every step.
          Default is ``'None'``.
      pos_weight (float|str, optional): A weight of positive examples. If type is str,
          it should equal to 'dynamic'. It will compute weight dynamically in every step.
          Default is ``'None'``.
      ignore_index (int64, optional): Specifies a target value that is ignored
          and does not contribute to the input gradient. Default ``255``.
      edge_label (bool, optional): Whether to use edge label. Default: False
  Shapes:
      logit (Tensor): The input predications tensor. 2-D tensor with shape: [N, *],
          N is batch_size, `*` means number of additional dimensions. The ``logit``
          is usually the output of Linear layer. Available dtype is float32, float64.
      label (Tensor): The target labels tensor. 2-D tensor with the same shape as
          ``logit``. The target labels which values should be numbers between 0 and 1.
          Available dtype is float32, float64.
  Returns:
      A callable object of BCEWithLogitsLoss.
  Examples:
      .. code-block:: python
          import paddle
          paddle.disable_static()
          logit = paddle.to_tensor([5.0, 1.0, 3.0], dtype="float32")
          label = paddle.to_tensor([1.0, 0.0, 1.0], dtype="float32")
          bce_logit_loss = paddle.nn.BCEWithLogitsLoss()
          output = bce_logit_loss(logit, label)
          print(output.numpy())  # [0.45618808]
code: def __init__(
      self,
      weight=None,
      pos_weight=None,
      ignore_index=255,
      edge_label=False,
  ):
      super().__init__()
      self.weight = weight
      self.pos_weight = pos_weight
      self.ignore_index = ignore_index
      self.edge_label = edge_label
      self.EPS = 1e-10
  
      if self.weight is not None:
          if isinstance(self.weight, str):
              if self.weight != "dynamic":
                  raise ValueError(
                      "if type of `weight` is str, it should equal to 'dynamic', but it is {}".format(
                          self.weight
                      )
                  )
          elif isinstance(self.weight, paddle.VarBase):
              raise TypeError(
                  "The type of `weight` is wrong, it should be Tensor or str, but it is {}".format(
                      type(self.weight)
                  )
              )
  
      if self.pos_weight is not None:
          if isinstance(self.pos_weight, str):
              if self.pos_weight != "dynamic":
                  raise ValueError(
                      "if type of `pos_weight` is str, it should equal to 'dynamic', but it is {}".format(
                          self.pos_weight
                      )
                  )
          elif isinstance(self.pos_weight, float):
              self.pos_weight = paddle.to_tensor(
                  self.pos_weight, dtype="float32"
              )
          else:
              raise TypeError(
                  "The type of `pos_weight` is wrong, it should be float or str, but it is {}".format(
                      type(self.pos_weight)
                  )
              )
  
file_path: PaddleSeg/contrib/MedicalSeg/medicalseg/models/losses/binary_cross_entropy_loss.py
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  from medicalseg.cvlibs import manager
label_desc: Use image node_id 1 to create a new BCELoss object from inherited base classes: nn with example: obj = BCELoss(weight, pos_weight, ignore_index, edge_label)