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: Perform forward propagation and loss calculation of the detection
  roi on the features of the upstream network.
  
  Args:
      x (tuple[Tensor]): List of multi-level img features.
      rpn_results_list (List[:obj:`InstanceData`]): List of region
          proposals.
      batch_data_samples (list[:obj:`DetDataSample`]): The batch
          data samples. It usually includes information such
          as `gt_instance` or `gt_panoptic_seg` or `gt_sem_seg`.
  
  Returns:
      dict: a dictionary of loss components of all stage.
docstr_tok: ["Perform","forward","propagation","and","loss","calculation","of","the","detection","roi","on","the","features","of","the","upstream","network",".","Args",":","x","(","tuple","[","Tensor","]",")",":","List","of","multi-level","img","features",".","rpn_results_list","(","List","[",":","obj",":","`","InstanceData","`","]",")",":","List","of","region","proposals",".","batch_data_samples","(","list","[",":","obj",":","`","DetDataSample","`","]",")",":","The","batch","data","samples",".","It","usually","includes","information","such","as","`","gt_instance","`","or","`","gt_panoptic_seg","`","or","`","gt_sem_seg","`",".","Returns",":","dict",":","a","dictionary","of","loss","components","of","all","stage","."]
code: def loss(
      self,
      x: Tuple[Tensor],
      rpn_results_list: InstanceList,
      batch_data_samples: SampleList,
  ) -> dict:
      """Perform forward propagation and loss calculation of the detection
      roi on the features of the upstream network.
  
      Args:
          x (tuple[Tensor]): List of multi-level img features.
          rpn_results_list (List[:obj:`InstanceData`]): List of region
              proposals.
          batch_data_samples (list[:obj:`DetDataSample`]): The batch
              data samples. It usually includes information such
              as `gt_instance` or `gt_panoptic_seg` or `gt_sem_seg`.
  
      Returns:
          dict: a dictionary of loss components of all stage.
      """
      outputs = unpack_gt_instances(batch_data_samples)
      (
          batch_gt_instances,
          batch_gt_instances_ignore,
          batch_img_metas,
      ) = outputs
  
      object_feats = torch.cat(
          [res.pop("features")[None, ...] for res in rpn_results_list]
      )
      results_list = rpn_results_list
      losses = {}
      for stage in range(self.num_stages):
          stage_loss_weight = self.stage_loss_weights[stage]
  
          # bbox head forward and loss
          bbox_results = self.bbox_loss(
              stage=stage,
              x=x,
              object_feats=object_feats,
              results_list=results_list,
              batch_img_metas=batch_img_metas,
              batch_gt_instances=batch_gt_instances,
          )
  
          for name, value in bbox_results["loss_bbox"].items():
              losses[f"s{stage}.{name}"] = (
                  value * stage_loss_weight if "loss" in name else value
              )
  
          if self.with_mask:
              mask_results = self.mask_loss(
                  stage=stage,
                  x=x,
                  bbox_results=bbox_results,
                  batch_gt_instances=batch_gt_instances,
                  rcnn_train_cfg=self.train_cfg[stage],
              )
  
              for name, value in mask_results["loss_mask"].items():
                  losses[f"s{stage}.{name}"] = (
                      value * stage_loss_weight
                      if "loss" in name
                      else value
                  )
  
          object_feats = bbox_results["object_feats"]
          results_list = bbox_results["results_list"]
      return losses
  
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 6 for calling the SparseRoIHead obj's underlying member method code with example usage: obj.loss(x, rpn_results_list, batch_data_samples) and returns: losses