class_docstr: Mask IoU Head.
  
  This head predicts the IoU of predicted masks and corresponding gt masks.
  
  Args:
      num_convs (int): The number of convolution layers. Defaults to 4.
      num_fcs (int): The number of fully connected layers. Defaults to 2.
      roi_feat_size (int): RoI feature size. Default to 14.
      in_channels (int): The channel number of inputs features.
          Defaults to 256.
      conv_out_channels (int): The feature channels of convolution layers.
          Defaults to 256.
      fc_out_channels (int): The feature channels of fully connected layers.
          Defaults to 1024.
      num_classes (int): Number of categories excluding the background
          category. Defaults to 80.
      loss_iou (:obj:`ConfigDict` or dict): IoU loss.
      init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or             dict], optional): Initialization config dict.
class_docstr_tok: ["Mask","IoU","Head",".","This","head","predicts","the","IoU","of","predicted","masks","and","corresponding","gt","masks",".","Args",":","num_convs","(","int",")",":","The","number","of","convolution","layers",".","Defaults","to","4.","num_fcs","(","int",")",":","The","number","of","fully","connected","layers",".","Defaults","to","2.","roi_feat_size","(","int",")",":","RoI","feature","size",".","Default","to","14.","in_channels","(","int",")",":","The","channel","number","of","inputs","features",".","Defaults","to","256.","conv_out_channels","(","int",")",":","The","feature","channels","of","convolution","layers",".","Defaults","to","256.","fc_out_channels","(","int",")",":","The","feature","channels","of","fully","connected","layers",".","Defaults","to","1024.","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","Defaults","to","80.","loss_iou","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","IoU","loss",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict","or","list","[",":","obj",":","`","ConfigDict","`","or","dict","]",",","optional",")",":","Initialization","config","dict","."]
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.
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance.  It includes ``masks`` inside.
      mask_preds (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 (obj:`ConfigDict`): 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",".","batch_gt_instances","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Batch","of","gt_instance",".","It","includes","``","masks","``","inside",".","mask_preds","(","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","(","obj",":","`","ConfigDict","`",")",":","Training","config","for","R-CNN","part",".","Returns",":","Tensor",":","mask","iou","target","(","length","==","num","positive",")","."]
code: def get_targets(
      self,
      sampling_results: List[SamplingResult],
      batch_gt_instances: InstanceList,
      mask_preds: Tensor,
      mask_targets: Tensor,
      rcnn_train_cfg: ConfigDict,
  ) -> Tensor:
      """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.
          batch_gt_instances (list[:obj:`InstanceData`]): Batch of
              gt_instance.  It includes ``masks`` inside.
          mask_preds (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 (obj:`ConfigDict`): Training config for R-CNN part.
  
      Returns:
          Tensor: mask iou target (length == num positive).
      """
      pos_proposals = [res.pos_priors for res in sampling_results]
      pos_assigned_gt_inds = [
          res.pos_assigned_gt_inds for res in sampling_results
      ]
      gt_masks = [res.masks for res in batch_gt_instances]
  
      # 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_preds = (mask_preds > rcnn_train_cfg.mask_thr_binary).float()
      mask_pred_areas = mask_preds.sum((-1, -2))
  
      # mask_preds and mask_targets are binary maps
      overlap_areas = (mask_preds * 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
  
imports: from typing import List, Tuple
  import numpy
  import torch
  import torch.nn
  from mmcv.cnn import Conv2d, Linear, MaxPool2d
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModule
  from mmengine.structures import InstanceData
  from torch import Tensor
  from torch.nn.modules.utils import _pair
  from mmdet.models.task_modules.samplers import SamplingResult
  from mmdet.registry import MODELS
  from mmdet.utils import ConfigType, InstanceList, OptMultiConfig
label_desc: Use image node_id 4 for calling the MaskIoUHead obj's underlying member method code with example usage: obj.get_targets(sampling_results, batch_gt_instances, mask_preds, mask_targets, rcnn_train_cfg) and returns: mask_iou_targets