class_docstr: Hybrid task cascade roi head including one bbox head and one mask head.
  
  https://arxiv.org/abs/1901.07518
  
  Args:
      num_stages (int): Number of cascade stages.
      stage_loss_weights (list[float]): Loss weight for every stage.
      semantic_roi_extractor (:obj:`ConfigDict` or dict, optional):
          Config of semantic roi extractor. Defaults to None.
      Semantic_head (:obj:`ConfigDict` or dict, optional):
          Config of semantic head. Defaults to None.
      interleaved (bool): Whether to interleaves the box branch and mask
          branch. If True, the mask branch can take the refined bounding
          box predictions. Defaults to True.
      mask_info_flow (bool): Whether to turn on the mask information flow,
          which means that feeding the mask features of the preceding stage
          to the current stage. Defaults to True.
docstr: Perform forward propagation of the mask head and predict detection
  results on the features of the upstream network.
  
  Args:
      x (tuple[Tensor]): Feature maps of all scale level.
      semantic_feat (Tensor): Semantic feature.
      batch_img_metas (list[dict]): List of image information.
      results_list (list[:obj:`InstanceData`]): Detection results of
          each image.
      rescale (bool): If True, return boxes in original image space.
          Defaults to False.
  
  Returns:
      list[:obj:`InstanceData`]: Detection results of each image
      after the post process.
      Each item usually contains following keys.
  
          - scores (Tensor): Classification scores, has a shape
            (num_instance, )
          - labels (Tensor): Labels of bboxes, has a shape
            (num_instances, ).
          - bboxes (Tensor): Has a shape (num_instances, 4),
            the last dimension 4 arrange as (x1, y1, x2, y2).
          - masks (Tensor): Has a shape (num_instances, H, W).
docstr_tok: ["Perform","forward","propagation","of","the","mask","head","and","predict","detection","results","on","the","features","of","the","upstream","network",".","Args",":","x","(","tuple","[","Tensor","]",")",":","Feature","maps","of","all","scale","level",".","semantic_feat","(","Tensor",")",":","Semantic","feature",".","batch_img_metas","(","list","[","dict","]",")",":","List","of","image","information",".","results_list","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Detection","results","of","each","image",".","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Defaults","to","False",".","Returns",":","list","[",":","obj",":","`","InstanceData","`","]",":","Detection","results","of","each","image","after","the","post","process",".","Each","item","usually","contains","following","keys",".","-","scores","(","Tensor",")",":","Classification","scores",",","has","a","shape","(","num_instance",",",")","-","labels","(","Tensor",")",":","Labels","of","bboxes",",","has","a","shape","(","num_instances",",",")",".","-","bboxes","(","Tensor",")",":","Has","a","shape","(","num_instances",",","4",")",",","the","last","dimension","4","arrange","as","(","x1",",","y1",",","x2",",","y2",")",".","-","masks","(","Tensor",")",":","Has","a","shape","(","num_instances",",","H",",","W",")","."]
code: def predict_mask(
      self,
      x: Tuple[Tensor],
      semantic_heat: Tensor,
      batch_img_metas: List[dict],
      results_list: InstanceList,
      rescale: bool = False,
  ) -> InstanceList:
      """Perform forward propagation of the mask head and predict detection
      results on the features of the upstream network.
  
      Args:
          x (tuple[Tensor]): Feature maps of all scale level.
          semantic_feat (Tensor): Semantic feature.
          batch_img_metas (list[dict]): List of image information.
          results_list (list[:obj:`InstanceData`]): Detection results of
              each image.
          rescale (bool): If True, return boxes in original image space.
              Defaults to False.
  
      Returns:
          list[:obj:`InstanceData`]: Detection results of each image
          after the post process.
          Each item usually contains following keys.
  
              - scores (Tensor): Classification scores, has a shape
                (num_instance, )
              - labels (Tensor): Labels of bboxes, has a shape
                (num_instances, ).
              - bboxes (Tensor): Has a shape (num_instances, 4),
                the last dimension 4 arrange as (x1, y1, x2, y2).
              - masks (Tensor): Has a shape (num_instances, H, W).
      """
      num_imgs = len(batch_img_metas)
      bboxes = [res.bboxes for res in results_list]
      mask_rois = bbox2roi(bboxes)
      if mask_rois.shape[0] == 0:
          results_list = empty_instances(
              batch_img_metas=batch_img_metas,
              device=mask_rois.device,
              task_type="mask",
              instance_results=results_list,
              mask_thr_binary=self.test_cfg.mask_thr_binary,
          )
          return results_list
  
      num_mask_rois_per_img = [len(res) for res in results_list]
      mask_results = self._mask_forward(
          stage=-1,
          x=x,
          rois=mask_rois,
          semantic_feat=semantic_heat,
          training=False,
      )
      # split batch mask prediction back to each image
      aug_masks = [
          [
              mask.sigmoid().detach()
              for mask in mask_preds.split(num_mask_rois_per_img, 0)
          ]
          for mask_preds in mask_results["mask_preds"]
      ]
  
      merged_masks = []
      for i in range(num_imgs):
          aug_mask = [mask[i] for mask in aug_masks]
          merged_mask = merge_aug_masks(aug_mask, batch_img_metas[i])
          merged_masks.append(merged_mask)
  
      results_list = self.mask_head[-1].predict_by_feat(
          mask_preds=merged_masks,
          results_list=results_list,
          batch_img_metas=batch_img_metas,
          rcnn_test_cfg=self.test_cfg,
          rescale=rescale,
          activate_map=True,
      )
  
      return results_list
  
imports: from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  from torch import Tensor
  from mmdet.models.test_time_augs import merge_aug_masks
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox2roi
  from mmdet.utils import InstanceList, OptConfigType
  from ..layers import adaptive_avg_pool2d
  from ..task_modules.samplers import SamplingResult
  from ..utils import empty_instances, unpack_gt_instances
  from .cascade_roi_head import CascadeRoIHead
label_desc: Use image node_id 9 for calling the HybridTaskCascadeRoIHead obj's underlying member method code with example usage: obj.predict_mask(x, semantic_heat, batch_img_metas, results_list, rescale) and returns: results_list, results_list