class_docstr: Masked dice loss.
  
  Args:
      eps (float, optional): Eps to avoid zero-divison error.  Defaults to
          1e-6.
class_docstr_tok: ["Masked","dice","loss",".","Args",":","eps","(","float",",","optional",")",":","Eps","to","avoid","zero-divison","error",".","Defaults","to","1e-6","."]
docstr: Forward function.
  
  Args:
      pred (torch.Tensor): The prediction in any shape.
      gt (torch.Tensor): The learning target of the prediction in the
          same shape as pred.
      mask (torch.Tensor, optional): Binary mask in the same shape of
          pred, indicating positive regions to calculate the loss. Whole
          region will be taken into account if not provided. Defaults to
          None.
  
  Returns:
      torch.Tensor: The loss value.
docstr_tok: ["Forward","function",".","Args",":","pred","(","torch.Tensor",")",":","The","prediction","in","any","shape",".","gt","(","torch.Tensor",")",":","The","learning","target","of","the","prediction","in","the","same","shape","as","pred",".","mask","(","torch.Tensor",",","optional",")",":","Binary","mask","in","the","same","shape","of","pred",",","indicating","positive","regions","to","calculate","the","loss",".","Whole","region","will","be","taken","into","account","if","not","provided",".","Defaults","to","None",".","Returns",":","torch.Tensor",":","The","loss","value","."]
code: def forward(
      self,
      pred: torch.Tensor,
      gt: torch.Tensor,
      mask: Optional[torch.Tensor] = None,
  ) -> torch.Tensor:
      """Forward function.
  
      Args:
          pred (torch.Tensor): The prediction in any shape.
          gt (torch.Tensor): The learning target of the prediction in the
              same shape as pred.
          mask (torch.Tensor, optional): Binary mask in the same shape of
              pred, indicating positive regions to calculate the loss. Whole
              region will be taken into account if not provided. Defaults to
              None.
  
      Returns:
          torch.Tensor: The loss value.
      """
  
      assert pred.size() == gt.size() and gt.numel() > 0
      if mask is None:
          mask = torch.ones_like(gt)
      assert mask.size() == gt.size()
  
      pred = pred.contiguous().view(pred.size(0), -1)
      gt = gt.contiguous().view(gt.size(0), -1)
  
      mask = mask.contiguous().view(mask.size(0), -1)
      pred = pred * mask
      gt = gt * mask
  
      dice_coeff = (2 * (pred * gt).sum()) / (
          pred.sum() + gt.sum() + self.eps
      )
  
      return 1 - dice_coeff
  
file_path: mmocr/mmocr/models/common/losses/dice_loss.py
imports: from typing import Optional
  import torch
  import torch.nn
  from mmocr.registry import MODELS
label_desc: Use image node_id 2 for calling the MaskedDiceLoss obj's underlying member method code with example usage: obj.forward(pred, gt, mask) and returns: unknown