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.
code: def __init__(
      self,
      num_stages: int = 6,
      stage_loss_weights: Tuple[float] = (1, 1, 1, 1, 1, 1),
      proposal_feature_channel: int = 256,
      bbox_roi_extractor: ConfigType = dict(
          type="SingleRoIExtractor",
          roi_layer=dict(
              type="RoIAlign", output_size=7, sampling_ratio=2
          ),
          out_channels=256,
          featmap_strides=[4, 8, 16, 32],
      ),
      mask_roi_extractor: OptConfigType = None,
      bbox_head: ConfigType = dict(
          type="DIIHead",
          num_classes=80,
          num_fcs=2,
          num_heads=8,
          num_cls_fcs=1,
          num_reg_fcs=3,
          feedforward_channels=2048,
          hidden_channels=256,
          dropout=0.0,
          roi_feat_size=7,
          ffn_act_cfg=dict(type="ReLU", inplace=True),
      ),
      mask_head: OptConfigType = None,
      train_cfg: OptConfigType = None,
      test_cfg: OptConfigType = None,
      init_cfg: OptConfigType = None,
  ) -> None:
      assert bbox_roi_extractor is not None
      assert bbox_head is not None
      assert len(stage_loss_weights) == num_stages
      self.num_stages = num_stages
      self.stage_loss_weights = stage_loss_weights
      self.proposal_feature_channel = proposal_feature_channel
      super().__init__(
          num_stages=num_stages,
          stage_loss_weights=stage_loss_weights,
          bbox_roi_extractor=bbox_roi_extractor,
          mask_roi_extractor=mask_roi_extractor,
          bbox_head=bbox_head,
          mask_head=mask_head,
          train_cfg=train_cfg,
          test_cfg=test_cfg,
          init_cfg=init_cfg,
      )
      # train_cfg would be None when run the test.py
      if train_cfg is not None:
          for stage in range(num_stages):
              assert isinstance(
                  self.bbox_sampler[stage], PseudoSampler
              ), "Sparse R-CNN and QueryInst only support `PseudoSampler`"
  
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 1 to create a new SparseRoIHead object from inherited base classes: CascadeRoIHead with example: obj = SparseRoIHead(num_stages, stage_loss_weights, proposal_feature_channel, bbox_roi_extractor, mask_roi_extractor, bbox_head, mask_head, train_cfg, test_cfg, init_cfg)