class_docstr: Mask IoU Head.
  
  This head predicts the IoU of predicted masks and corresponding gt masks.
docstr: Compute target of mask IoU.
  
  Mask IoU target is the IoU of the predicted mask (inside a bbox) and
  the gt mask of corresponding gt mask (the whole instance).
  The intersection area is computed inside the bbox, and the gt mask area
  is computed with two steps, firstly we compute the gt area inside the
  bbox, then divide it by the area ratio of gt area inside the bbox and
  the gt area of the whole instance.
  
  Args:
      sampling_results (list[:obj:`SamplingResult`]): sampling results.
      gt_masks (BitmapMask | PolygonMask): Gt masks (the whole instance)
          of each image, with the same shape of the input image.
      mask_pred (Tensor): Predicted masks of each positive proposal,
          shape (num_pos, h, w).
      mask_targets (Tensor): Gt mask of each positive proposal,
          binary map of the shape (num_pos, h, w).
      rcnn_train_cfg (dict): Training config for R-CNN part.
  
  Returns:
      Tensor: mask iou target (length == num positive).
docstr_tok: ["Compute","target","of","mask","IoU",".","Mask","IoU","target","is","the","IoU","of","the","predicted","mask","(","inside","a","bbox",")","and","the","gt","mask","of","corresponding","gt","mask","(","the","whole","instance",")",".","The","intersection","area","is","computed","inside","the","bbox",",","and","the","gt","mask","area","is","computed","with","two","steps",",","firstly","we","compute","the","gt","area","inside","the","bbox",",","then","divide","it","by","the","area","ratio","of","gt","area","inside","the","bbox","and","the","gt","area","of","the","whole","instance",".","Args",":","sampling_results","(","list","[",":","obj",":","`","SamplingResult","`","]",")",":","sampling","results",".","gt_masks","(","BitmapMask","|","PolygonMask",")",":","Gt","masks","(","the","whole","instance",")","of","each","image",",","with","the","same","shape","of","the","input","image",".","mask_pred","(","Tensor",")",":","Predicted","masks","of","each","positive","proposal",",","shape","(","num_pos",",","h",",","w",")",".","mask_targets","(","Tensor",")",":","Gt","mask","of","each","positive","proposal",",","binary","map","of","the","shape","(","num_pos",",","h",",","w",")",".","rcnn_train_cfg","(","dict",")",":","Training","config","for","R-CNN","part",".","Returns",":","Tensor",":","mask","iou","target","(","length","==","num","positive",")","."]
code: def get_targets(
      self,
      sampling_results,
      gt_masks,
      mask_pred,
      mask_targets,
      rcnn_train_cfg,
  ):
      """Compute target of mask IoU.
  
      Mask IoU target is the IoU of the predicted mask (inside a bbox) and
      the gt mask of corresponding gt mask (the whole instance).
      The intersection area is computed inside the bbox, and the gt mask area
      is computed with two steps, firstly we compute the gt area inside the
      bbox, then divide it by the area ratio of gt area inside the bbox and
      the gt area of the whole instance.
  
      Args:
          sampling_results (list[:obj:`SamplingResult`]): sampling results.
          gt_masks (BitmapMask | PolygonMask): Gt masks (the whole instance)
              of each image, with the same shape of the input image.
          mask_pred (Tensor): Predicted masks of each positive proposal,
              shape (num_pos, h, w).
          mask_targets (Tensor): Gt mask of each positive proposal,
              binary map of the shape (num_pos, h, w).
          rcnn_train_cfg (dict): Training config for R-CNN part.
  
      Returns:
          Tensor: mask iou target (length == num positive).
      """
      pos_proposals = [res.pos_bboxes for res in sampling_results]
      pos_assigned_gt_inds = [
          res.pos_assigned_gt_inds for res in sampling_results
      ]
  
      # compute the area ratio of gt areas inside the proposals and
      # the whole instance
      area_ratios = map(
          self._get_area_ratio,
          pos_proposals,
          pos_assigned_gt_inds,
          gt_masks,
      )
      area_ratios = torch.cat(list(area_ratios))
      assert mask_targets.size(0) == area_ratios.size(0)
  
      mask_pred = (mask_pred > rcnn_train_cfg.mask_thr_binary).float()
      mask_pred_areas = mask_pred.sum((-1, -2))
  
      # mask_pred and mask_targets are binary maps
      overlap_areas = (mask_pred * mask_targets).sum((-1, -2))
  
      # compute the mask area of the whole instance
      gt_full_areas = mask_targets.sum((-1, -2)) / (area_ratios + 1e-7)
  
      mask_iou_targets = overlap_areas / (
          mask_pred_areas + gt_full_areas - overlap_areas
      )
      return mask_iou_targets
  
file_path: insightface/detection/scrfd/mmdet/models/roi_heads/mask_heads/maskiou_head.py
imports: import numpy
  import torch
  import torch.nn
  from mmcv.cnn import Conv2d, Linear, MaxPool2d, kaiming_init, normal_init
  from mmcv.runner import force_fp32
  from torch.nn.modules.utils import _pair
  from mmdet.models.builder import HEADS, build_loss
label_desc: Use image node_id 5 for calling the MaskIoUHead obj's underlying member method code with example usage: obj.get_targets(sampling_results, gt_masks, mask_pred, mask_targets, rcnn_train_cfg) and returns: mask_iou_targets