docstr: Mask head forward function used in both training and testing.
  
  Args:
      stage (int): The current stage in Cascade RoI Head.
      x (tuple[Tensor]): Tuple of multi-level img features.
      rois (Tensor): RoIs with the shape (n, 5) where the first
          column indicates batch id of each RoI.
  
  Returns:
      dict: Usually returns a dictionary with keys:
  
          - `mask_preds` (Tensor): Mask prediction.
docstr_tok: ["Mask","head","forward","function","used","in","both","training","and","testing",".","Args",":","stage","(","int",")",":","The","current","stage","in","Cascade","RoI","Head",".","x","(","tuple","[","Tensor","]",")",":","Tuple","of","multi-level","img","features",".","rois","(","Tensor",")",":","RoIs","with","the","shape","(","n",",","5",")","where","the","first","column","indicates","batch","id","of","each","RoI",".","Returns",":","dict",":","Usually","returns","a","dictionary","with","keys",":","-","`","mask_preds","`","(","Tensor",")",":","Mask","prediction","."]
code: def _mask_forward(self, x: Tuple[Tensor], rois: Tensor) -> dict:
      """Mask head forward function used in both training and testing.
  
      Args:
          stage (int): The current stage in Cascade RoI Head.
          x (tuple[Tensor]): Tuple of multi-level img features.
          rois (Tensor): RoIs with the shape (n, 5) where the first
              column indicates batch id of each RoI.
  
      Returns:
          dict: Usually returns a dictionary with keys:
  
              - `mask_preds` (Tensor): Mask prediction.
      """
      mask_feats = self.mask_roi_extractor(
          x[: self.mask_roi_extractor.num_inputs], rois
      )
      # do not support caffe_c4 model anymore
      mask_preds = self.mask_head(mask_feats)
  
      mask_results = dict(mask_preds=mask_preds)
      return mask_results
  
imports: from typing import List, Sequence, Tuple
  import torch
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.roi_heads import CascadeRoIHead
  from mmdet.models.task_modules.samplers import SamplingResult
  from mmdet.models.test_time_augs import merge_aug_masks
  from mmdet.models.utils.misc import empty_instances
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox2roi, get_box_tensor
  from mmdet.utils import ConfigType, InstanceList, MultiConfig
label_desc: Use image node_id 5 for calling the DeticRoIHead obj's underlying member method code with example usage: obj._mask_forward(x, rois) and returns: mask_results