docstr: The BalanceLoss for Differentiable Binarization text detection
  args:
      balance_loss (bool): whether balance loss or not, default is True
      main_loss_type (str): can only be one of ['CrossEntropy','DiceLoss',
          'Euclidean','BCELoss', 'MaskL1Loss'], default is  'DiceLoss'.
      negative_ratio (int|float): float, default is 3.
      return_origin (bool): whether return unbalanced loss or not, default is False.
      eps (float): default is 1e-6.
docstr_tok: ["The","BalanceLoss","for","Differentiable","Binarization","text","detection","args",":","balance_loss","(","bool",")",":","whether","balance","loss","or","not",",","default","is","True","main_loss_type","(","str",")",":","can","only","be","one","of","[","'CrossEntropy","'",",","'DiceLoss","'",",","'Euclidean","'",",","'BCELoss","'",",","'MaskL1Loss","'","]",",","default","is","'DiceLoss","'",".","negative_ratio","(","int|float",")",":","float",",","default","is","3.","return_origin","(","bool",")",":","whether","return","unbalanced","loss","or","not",",","default","is","False",".","eps","(","float",")",":","default","is","1e-6","."]
code: def __init__(
      self,
      balance_loss=True,
      main_loss_type="DiceLoss",
      negative_ratio=3,
      return_origin=False,
      eps=1e-6,
      **kwargs,
  ):
      """
      The BalanceLoss for Differentiable Binarization text detection
      args:
          balance_loss (bool): whether balance loss or not, default is True
          main_loss_type (str): can only be one of ['CrossEntropy','DiceLoss',
              'Euclidean','BCELoss', 'MaskL1Loss'], default is  'DiceLoss'.
          negative_ratio (int|float): float, default is 3.
          return_origin (bool): whether return unbalanced loss or not, default is False.
          eps (float): default is 1e-6.
      """
      super(BalanceLoss, self).__init__()
      self.balance_loss = balance_loss
      self.main_loss_type = main_loss_type
      self.negative_ratio = negative_ratio
      self.return_origin = return_origin
      self.eps = eps
  
      if self.main_loss_type == "CrossEntropy":
          self.loss = nn.CrossEntropyLoss()
      elif self.main_loss_type == "Euclidean":
          self.loss = nn.MSELoss()
      elif self.main_loss_type == "DiceLoss":
          self.loss = DiceLoss(self.eps)
      elif self.main_loss_type == "BCELoss":
          self.loss = BCELoss(reduction="none")
      elif self.main_loss_type == "MaskL1Loss":
          self.loss = MaskL1Loss(self.eps)
      else:
          loss_type = [
              "CrossEntropy",
              "DiceLoss",
              "Euclidean",
              "BCELoss",
              "MaskL1Loss",
          ]
          raise Exception(
              "main_loss_type in BalanceLoss() can only be one of {}".format(
                  loss_type
              )
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import paddle
  from paddle import nn
  import paddle.nn.functional
label_desc: Use image node_id 1 to create a new BalanceLoss object from inherited base classes: nn with example: obj = BalanceLoss(balance_loss, main_loss_type, negative_ratio, return_origin, eps)