class_docstr: Hybrid task cascade roi head including one bbox head and one mask head.
  
  https://arxiv.org/abs/1901.07518
  
  Args:
      num_stages (int): Number of cascade stages.
      stage_loss_weights (list[float]): Loss weight for every stage.
      semantic_roi_extractor (:obj:`ConfigDict` or dict, optional):
          Config of semantic roi extractor. Defaults to None.
      Semantic_head (:obj:`ConfigDict` or dict, optional):
          Config of semantic head. Defaults to None.
      interleaved (bool): Whether to interleaves the box branch and mask
          branch. If True, the mask branch can take the refined bounding
          box predictions. Defaults to True.
      mask_info_flow (bool): Whether to turn on the mask information flow,
          which means that feeding the mask features of the preceding stage
          to the current stage. Defaults to True.
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[str, Tensor]: A dictionary of loss components
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","[","str",",","Tensor","]",":","A","dictionary","of","loss","components"]
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[str, Tensor]: A dictionary of loss components
      """
      assert len(rpn_results_list) == len(batch_data_samples)
      outputs = unpack_gt_instances(batch_data_samples)
      (
          batch_gt_instances,
          batch_gt_instances_ignore,
          batch_img_metas,
      ) = outputs
  
      # semantic segmentation part
      # 2 outputs: segmentation prediction and embedded features
      losses = dict()
      if self.with_semantic:
          gt_semantic_segs = [
              data_sample.gt_sem_seg.sem_seg
              for data_sample in batch_data_samples
          ]
          gt_semantic_segs = torch.stack(gt_semantic_segs)
          semantic_pred, semantic_feat = self.semantic_head(x)
          loss_seg = self.semantic_head.loss(
              semantic_pred, gt_semantic_segs
          )
          losses["loss_semantic_seg"] = loss_seg
      else:
          semantic_feat = None
  
      results_list = rpn_results_list
      num_imgs = len(batch_img_metas)
      for stage in range(self.num_stages):
          self.current_stage = stage
  
          stage_loss_weight = self.stage_loss_weights[stage]
  
          # assign gts and sample proposals
          sampling_results = []
          bbox_assigner = self.bbox_assigner[stage]
          bbox_sampler = self.bbox_sampler[stage]
          for i in range(num_imgs):
              results = results_list[i]
              # rename rpn_results.bboxes to rpn_results.priors
              if "bboxes" in results:
                  results.priors = results.pop("bboxes")
  
              assign_result = bbox_assigner.assign(
                  results,
                  batch_gt_instances[i],
                  batch_gt_instances_ignore[i],
              )
              sampling_result = bbox_sampler.sample(
                  assign_result,
                  results,
                  batch_gt_instances[i],
                  feats=[lvl_feat[i][None] for lvl_feat in x],
              )
              sampling_results.append(sampling_result)
  
          # bbox head forward and loss
          bbox_results = self.bbox_loss(
              stage=stage,
              x=x,
              sampling_results=sampling_results,
              semantic_feat=semantic_feat,
          )
  
          for name, value in bbox_results["loss_bbox"].items():
              losses[f"s{stage}.{name}"] = (
                  value * stage_loss_weight if "loss" in name else value
              )
  
          # mask head forward and loss
          if self.with_mask:
              # interleaved execution: use regressed bboxes by the box branch
              # to train the mask branch
              if self.interleaved:
                  bbox_head = self.bbox_head[stage]
                  with torch.no_grad():
                      results_list = bbox_head.refine_bboxes(
                          sampling_results,
                          bbox_results,
                          batch_img_metas,
                      )
                      # re-assign and sample 512 RoIs from 512 RoIs
                      sampling_results = []
                      for i in range(num_imgs):
                          results = results_list[i]
                          # rename rpn_results.bboxes to rpn_results.priors
                          results.priors = results.pop("bboxes")
                          assign_result = bbox_assigner.assign(
                              results,
                              batch_gt_instances[i],
                              batch_gt_instances_ignore[i],
                          )
                          sampling_result = bbox_sampler.sample(
                              assign_result,
                              results,
                              batch_gt_instances[i],
                              feats=[
                                  lvl_feat[i][None] for lvl_feat in x
                              ],
                          )
                          sampling_results.append(sampling_result)
              mask_results = self.mask_loss(
                  stage=stage,
                  x=x,
                  sampling_results=sampling_results,
                  batch_gt_instances=batch_gt_instances,
                  semantic_feat=semantic_feat,
              )
              for name, value in mask_results["loss_mask"].items():
                  losses[f"s{stage}.{name}"] = (
                      value * stage_loss_weight
                      if "loss" in name
                      else value
                  )
  
          # refine bboxes (same as Cascade R-CNN)
          if stage < self.num_stages - 1 and not self.interleaved:
              bbox_head = self.bbox_head[stage]
              with torch.no_grad():
                  results_list = bbox_head.refine_bboxes(
                      sampling_results=sampling_results,
                      bbox_results=bbox_results,
                      batch_img_metas=batch_img_metas,
                  )
  
      return losses
  
imports: from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  from torch import Tensor
  from mmdet.models.test_time_augs import merge_aug_masks
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox2roi
  from mmdet.utils import InstanceList, OptConfigType
  from ..layers import adaptive_avg_pool2d
  from ..task_modules.samplers import SamplingResult
  from ..utils import empty_instances, unpack_gt_instances
  from .cascade_roi_head import CascadeRoIHead
label_desc: Use image node_id 7 for calling the HybridTaskCascadeRoIHead obj's underlying member method code with example usage: obj.loss(x, rpn_results_list, batch_data_samples) and returns: losses