class_docstr: Cascade roi head including one bbox head and one mask head.
  
  https://arxiv.org/abs/1712.00726
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.
      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",".","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],
      batch_img_metas: List[dict],
      results_list: List[InstanceData],
      rescale: bool = False,
  ) -> List[InstanceData]:
      """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.
          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).
      """
      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,
              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]
      aug_masks = []
      for stage in range(self.num_stages):
          mask_results = self._mask_forward(stage, x, mask_rois)
          mask_preds = mask_results["mask_preds"]
          # split batch mask prediction back to each image
          mask_preds = mask_preds.split(num_mask_rois_per_img, 0)
          aug_masks.append([m.sigmoid().detach() for m in mask_preds])
  
      merged_masks = []
      for i in range(len(batch_img_metas)):
          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 List, Sequence, Tuple, Union
  import torch
  import torch.nn
  from mmengine.model import ModuleList
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.task_modules.samplers import SamplingResult
  from mmdet.models.test_time_augs import merge_aug_masks
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox2roi, get_box_tensor
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptConfigType, OptMultiConfig
  from ..utils.misc import empty_instances, unpack_gt_instances
  from .base_roi_head import BaseRoIHead
label_desc: Use image node_id 11 for calling the CascadeRoIHead obj's underlying member method code with example usage: obj.predict_mask(x, batch_img_metas, results_list, rescale) and returns: results_list, results_list