class_docstr: This part is partially derivated from:
  
  https://github.com/facebookresearch/detr/blob/main/models/detr.py.
class_docstr_tok: ["This","part","is","partially","derivated","from",":","https",":","\/\/github.com\/facebookresearch\/detr\/blob\/main\/models\/detr.py","."]
code: def loss_masks_with_iou_objectness(
      self, outputs, batch_gt_instances, indices, num_instances
  ):
      src_idx = self._get_src_permutation_idx(indices)
      tgt_idx = self._get_tgt_permutation_idx(indices)
      # Bx100xHxW
      assert "pred_masks" in outputs
      assert "pred_scores" in outputs
      src_iou_scores = outputs["pred_scores"]
      src_masks = outputs["pred_masks"]
      with torch.no_grad():
          target_masks = torch.cat(
              [
                  gt.masks.to_tensor(
                      dtype=src_masks.dtype, device=src_masks.device
                  )
                  for gt in batch_gt_instances
              ]
          )
      num_masks = [len(gt.masks) for gt in batch_gt_instances]
      target_masks = target_masks.to(src_masks)
      if len(target_masks) == 0:
          loss_dice = src_masks.sum() * 0.0
          loss_mask = src_masks.sum() * 0.0
          loss_objectness = src_iou_scores.sum() * 0.0
  
          return loss_objectness, loss_dice, loss_mask
  
      src_masks = src_masks[src_idx]
      target_masks = F.interpolate(
          target_masks[:, None],
          size=src_masks.shape[-2:],
          mode="bilinear",
          align_corners=False,
      ).squeeze(1)
  
      src_masks = src_masks.flatten(1)
      # FIXME: tgt_idx
      mix_tgt_idx = torch.zeros_like(tgt_idx[1])
      cum_sum = 0
      for num_mask in num_masks:
          mix_tgt_idx[cum_sum : cum_sum + num_mask] = cum_sum
          cum_sum += num_mask
      mix_tgt_idx += tgt_idx[1]
  
      target_masks = target_masks[mix_tgt_idx].flatten(1)
  
      with torch.no_grad():
          ious = compute_mask_iou(src_masks, target_masks)
  
      tgt_iou_scores = ious
      src_iou_scores = src_iou_scores[src_idx]
      tgt_iou_scores = tgt_iou_scores.flatten(0)
      src_iou_scores = src_iou_scores.flatten(0)
  
      loss_objectness = self.loss_obj(src_iou_scores, tgt_iou_scores)
      loss_dice = (
          self.loss_dice(src_masks, target_masks) / num_instances
      )
      loss_mask = self.loss_mask(src_masks, target_masks)
  
      return loss_objectness, loss_dice, loss_mask
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from scipy.optimize import linear_sum_assignment
  from torch.cuda.amp import autocast
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.utils import reduce_mean
label_desc: Use image node_id 5 for calling the SparseInstCriterion obj's underlying member method code with example usage: obj.loss_masks_with_iou_objectness(outputs, batch_gt_instances, indices, num_instances) and returns: loss_objectness,  loss_dice,  loss_mask, loss_objectness,  loss_dice,  loss_mask