class_docstr: The RoIHead for `Sparse R-CNN: End-to-End Object Detection with
  Learnable Proposals <https://arxiv.org/abs/2011.12450>`_
  and `Instances as Queries <http://arxiv.org/abs/2105.01928>`_
  
  Args:
      num_stages (int): Number of stage whole iterative process.
          Defaults to 6.
      stage_loss_weights (Tuple[float]): The loss
          weight of each stage. By default all stages have
          the same weight 1.
      bbox_roi_extractor (:obj:`ConfigDict` or dict): Config of box
          roi extractor.
      mask_roi_extractor (:obj:`ConfigDict` or dict): Config of mask
          roi extractor.
      bbox_head (:obj:`ConfigDict` or dict): Config of box head.
      mask_head (:obj:`ConfigDict` or dict): Config of mask head.
      train_cfg (:obj:`ConfigDict` or dict, Optional): Configuration
          information in train stage. Defaults to None.
      test_cfg (:obj:`ConfigDict` or dict, Optional): Configuration
          information in test stage. Defaults to None.
      init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or \
          dict]): Initialization config dict. Defaults to None.
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.
      attn_feats (Tensot): Intermediate feature get from the last
          diihead, has shape
          (batch_size*num_proposals, feature_dimensions)
  
  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",".","attn_feats","(","Tensot",")",":","Intermediate","feature","get","from","the","last","diihead",",","has","shape","(","batch_size","*","num_proposals",",","feature_dimensions",")","Returns",":","dict",":","Usually","returns","a","dictionary","with","keys",":","-","`","mask_preds","`","(","Tensor",")",":","Mask","prediction","."]
code: def _mask_forward(
      self, stage: int, x: Tuple[Tensor], rois: Tensor, attn_feats
  ) -> 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.
          attn_feats (Tensot): Intermediate feature get from the last
              diihead, has shape
              (batch_size*num_proposals, feature_dimensions)
  
      Returns:
          dict: Usually returns a dictionary with keys:
  
          - `mask_preds` (Tensor): Mask prediction.
      """
      mask_roi_extractor = self.mask_roi_extractor[stage]
      mask_head = self.mask_head[stage]
      mask_feats = mask_roi_extractor(
          x[: mask_roi_extractor.num_inputs], rois
      )
      # do not support caffe_c4 model anymore
      mask_preds = mask_head(mask_feats, attn_feats)
  
      mask_results = dict(mask_preds=mask_preds)
      return mask_results
  
imports: from typing import List, Tuple
  import torch
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.task_modules.samplers import PseudoSampler
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox2roi
  from mmdet.utils import ConfigType, InstanceList, OptConfigType
  from ..utils.misc import empty_instances, unpack_gt_instances
  from .cascade_roi_head import CascadeRoIHead
label_desc: Use image node_id 4 for calling the SparseRoIHead obj's underlying member method code with example usage: obj._mask_forward(stage, x, rois, attn_feats) and returns: mask_results