code: def loss_masks(
      self, pos_bbox_pred, mask_logits, targets, indices, avg_factor
  ):
      tgt_segm = [
          paddle.gather(tgt["gt_segm"], tgt_idx, axis=0)
          for tgt, (_, tgt_idx) in zip(targets, indices)
      ]
  
      tgt_masks = []
      for i in range(len(indices)):
          gt_segm = tgt_segm[i].unsqueeze(1)
          if len(gt_segm) == 0:
              continue
          boxes = pos_bbox_pred[i]
          boxes[:, 0::2] = paddle.clip(
              boxes[:, 0::2], min=0, max=gt_segm.shape[3]
          )
          boxes[:, 1::2] = paddle.clip(
              boxes[:, 1::2], min=0, max=gt_segm.shape[2]
          )
          boxes_num = paddle.to_tensor([1] * len(boxes), dtype="int32")
          gt_mask = paddle.vision.ops.roi_align(
              gt_segm,
              boxes,
              boxes_num,
              output_size=mask_logits.shape[-2:],
              aligned=True,
          )
          tgt_masks.append(gt_mask)
      tgt_masks = paddle.concat(tgt_masks).squeeze(1)
      tgt_masks = paddle.cast(tgt_masks >= 0.5, dtype="float32")
      tgt_masks.stop_gradient = True
  
      tgt_labels = paddle.concat(
          [
              paddle.gather(tgt["labels"], tgt_idx, axis=0)
              for tgt, (_, tgt_idx) in zip(targets, indices)
          ]
      )
  
      mask_label = F.one_hot(tgt_labels, self.num_classes).unsqueeze(
          [2, 3]
      )
      mask_label = paddle.expand_as(mask_label, mask_logits)
      mask_label.stop_gradient = True
  
      src_masks = paddle.gather_nd(
          mask_logits, paddle.nonzero(mask_label)
      )
      shape = mask_logits.shape
      src_masks = paddle.reshape(
          src_masks, [shape[0], shape[2], shape[3]]
      )
      src_masks = F.sigmoid(src_masks)
  
      X = src_masks.flatten(1)
      Y = tgt_masks.flatten(1)
      inter = paddle.sum(X * Y, 1)
      union = paddle.sum(X * X, 1) + paddle.sum(Y * Y, 1)
      dice = (2 * inter) / (union + 2e-5)
  
      loss_mask = (1 - dice).sum() / avg_factor
      losses = {"loss_mask": loss_mask * self.loss_weights["loss_mask"]}
      return losses
  
file_path: PaddleDetection/ppdet/modeling/losses/queryinst_loss.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import paddle
  import paddle.nn.functional
  from ppdet.core.workspace import register
  from ppdet.modeling.losses.iou_loss import GIoULoss
  from .sparsercnn_loss import HungarianMatcher
label_desc: Use image node_id 4 for calling the QueryInstLoss obj's underlying member method code with example usage: obj.loss_masks(pos_bbox_pred, mask_logits, targets, indices, avg_factor) and returns: losses