class_docstr: Implements the dice loss function.
  
  Args:
      ignore_index (int64): Specifies a target value that is ignored
          and does not contribute to the input gradient. Default ``255``.
      smooth (float32): laplace smoothing,
          to smooth dice loss and accelerate convergence. following:
          https://github.com/pytorch/pytorch/issues/1249#issuecomment-337999895
docstr: Computes DiceCoefficient as defined in https://arxiv.org/abs/1606.04797 given  a multi channel input and target.
  Assumes the input is a normalized probability, e.g. a result of Sigmoid or Softmax function.
  
  Args:
      input (torch.Tensor): NxCxSpatial input tensor
      target (torch.Tensor): NxCxSpatial target tensor
      epsilon (float): prevents division by zero
      weight (torch.Tensor): Cx1 tensor of weight per channel/class
docstr_tok: ["Computes","DiceCoefficient","as","defined","in","https",":","\/\/arxiv.org\/abs\/1606.04797","given","a","multi","channel","input","and","target",".","Assumes","the","input","is","a","normalized","probability",",","e.g",".","a","result","of","Sigmoid","or","Softmax","function",".","Args",":","input","(","torch.Tensor",")",":","NxCxSpatial","input","tensor","target","(","torch.Tensor",")",":","NxCxSpatial","target","tensor","epsilon","(","float",")",":","prevents","division","by","zero","weight","(","torch.Tensor",")",":","Cx1","tensor","of","weight","per","channel\/class"]
code: def compute_per_channel_dice(
      self, input, target, epsilon=1e-6, weight=None
  ):
      """
      Computes DiceCoefficient as defined in https://arxiv.org/abs/1606.04797 given  a multi channel input and target.
      Assumes the input is a normalized probability, e.g. a result of Sigmoid or Softmax function.
  
      Args:
          input (torch.Tensor): NxCxSpatial input tensor
          target (torch.Tensor): NxCxSpatial target tensor
          epsilon (float): prevents division by zero
          weight (torch.Tensor): Cx1 tensor of weight per channel/class
      """
  
      # input and target shapes must match
      assert (
          input.shape == target.shape
      ), "'input' and 'target' must have the same shape but input is {} and target is {}".format(
          input.shape, target.shape
      )
  
      input = flatten(input)  # C, N*D*H*W
      target = flatten(target)
      target = paddle.cast(target, "float32")
  
      # compute per channel Dice Coefficient
      intersect = (input * target).sum(
          -1
      )  # sum at the spatial dimension
      if weight is not None:
          intersect = (
              weight * intersect
          )  # give different class different weight
  
      # Use standard dice: (input + target).sum(-1) or V-Net extension: (input^2 + target^2).sum(-1)
      denominator = (input * input).sum(-1) + (target * target).sum(-1)
  
      return 2 * (intersect / paddle.clip(denominator, min=epsilon))
  
file_path: PaddleSeg/contrib/MedicalSeg/medicalseg/models/losses/dice_loss.py
imports: import paddle
  from paddle import nn
  import paddle.nn.functional
  from medicalseg.models.losses import flatten
  from medicalseg.cvlibs import manager
label_desc: Use image node_id 2 for calling the DiceLoss obj's underlying member method code with example usage: obj.compute_per_channel_dice(input, target, epsilon, weight) and returns: unknown