class_docstr: Cost of mask assignments based on dice losses.
  
  Args:
      pred_act (bool): Whether to apply sigmoid to mask_pred.
          Defaults to False.
      eps (float): Defaults to 1e-3.
      naive_dice (bool): If True, use the naive dice loss
          in which the power of the number in the denominator is
          the first power. If False, use the second power that
          is adopted by K-Net and SOLO. Defaults to True.
      weight (Union[float, int]): Cost weight. Defaults to 1.
class_docstr_tok: ["Cost","of","mask","assignments","based","on","dice","losses",".","Args",":","pred_act","(","bool",")",":","Whether","to","apply","sigmoid","to","mask_pred",".","Defaults","to","False",".","eps","(","float",")",":","Defaults","to","1e-3",".","naive_dice","(","bool",")",":","If","True",",","use","the","naive","dice","loss","in","which","the","power","of","the","number","in","the","denominator","is","the","first","power",".","If","False",",","use","the","second","power","that","is","adopted","by","K-Net","and","SOLO",".","Defaults","to","True",".","weight","(","Union","[","float",",","int","]",")",":","Cost","weight",".","Defaults","to","1","."]
docstr: Args:
      mask_preds (Tensor): Mask prediction in shape (num_queries, *).
      gt_masks (Tensor): Ground truth in shape (num_gt, *)
          store 0 or 1, 0 for negative class and 1 for
          positive class.
  
  Returns:
      Tensor: Dice cost matrix in shape (num_queries, num_gt).
code: def _binary_mask_dice_loss(
      self, mask_preds: Tensor, gt_masks: Tensor
  ) -> Tensor:
      """
      Args:
          mask_preds (Tensor): Mask prediction in shape (num_queries, *).
          gt_masks (Tensor): Ground truth in shape (num_gt, *)
              store 0 or 1, 0 for negative class and 1 for
              positive class.
  
      Returns:
          Tensor: Dice cost matrix in shape (num_queries, num_gt).
      """
      mask_preds = mask_preds.flatten(1)
      gt_masks = gt_masks.flatten(1).float()
      numerator = 2 * torch.einsum("nc,mc->nm", mask_preds, gt_masks)
      if self.naive_dice:
          denominator = (
              mask_preds.sum(-1)[:, None] + gt_masks.sum(-1)[None, :]
          )
      else:
          denominator = (
              mask_preds.pow(2).sum(1)[:, None]
              + gt_masks.pow(2).sum(1)[None, :]
          )
      loss = 1 - (numerator + self.eps) / (denominator + self.eps)
      return loss
  
imports: from abc import abstractmethod
  from typing import Optional, Union
  import torch
  import torch.nn.functional
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import TASK_UTILS
  from mmdet.structures.bbox import bbox_overlaps, bbox_xyxy_to_cxcywh
label_desc: Use image node_id 2 for calling the DiceCost obj's underlying member method code with example usage: obj._binary_mask_dice_loss(mask_preds, gt_masks) and returns: loss