docstr: DiceLoss function.
docstr_tok: ["DiceLoss","function","."]
code: def forward(self, pred, gt, mask, weights=None):
      """
      DiceLoss function.
      """
  
      assert pred.shape == gt.shape
      assert pred.shape == mask.shape
      if weights is not None:
          assert weights.shape == mask.shape
          mask = weights * mask
      intersection = paddle.sum(pred * gt * mask)
  
      union = paddle.sum(pred * mask) + paddle.sum(gt * mask) + self.eps
      loss = 1 - 2.0 * intersection / union
      assert loss <= 1
      return loss
  
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 2 for calling the DiceLoss obj's underlying member method code with example usage: obj.forward(pred, gt, mask, weights) and returns: loss