class_docstr: Cascade roi head including one bbox head and one mask head.
  
  https://arxiv.org/abs/1712.00726
docstr: Run forward function and calculate loss for box head in training.
  
  Args:
      stage (int): The current stage in Cascade RoI Head.
      x (tuple[Tensor]): List of multi-level img features.
      sampling_results (list["obj:`SamplingResult`]): Sampling results.
  
  Returns:
      dict: Usually returns a dictionary with keys:
  
          - `cls_score` (Tensor): Classification scores.
          - `bbox_pred` (Tensor): Box energies / deltas.
          - `bbox_feats` (Tensor): Extract bbox RoI features.
          - `loss_bbox` (dict): A dictionary of bbox loss components.
          - `rois` (Tensor): RoIs with the shape (n, 5) where the first
            column indicates batch id of each RoI.
          - `bbox_targets` (tuple):  Ground truth for proposals in a
            single image. Containing the following list of Tensors:
            (labels, label_weights, bbox_targets, bbox_weights)
docstr_tok: ["Run","forward","function","and","calculate","loss","for","box","head","in","training",".","Args",":","stage","(","int",")",":","The","current","stage","in","Cascade","RoI","Head",".","x","(","tuple","[","Tensor","]",")",":","List","of","multi-level","img","features",".","sampling_results","(","list","[","``","obj",":","`","SamplingResult","`","]",")",":","Sampling","results",".","Returns",":","dict",":","Usually","returns","a","dictionary","with","keys",":","-","`","cls_score","`","(","Tensor",")",":","Classification","scores",".","-","`","bbox_pred","`","(","Tensor",")",":","Box","energies","\/","deltas",".","-","`","bbox_feats","`","(","Tensor",")",":","Extract","bbox","RoI","features",".","-","`","loss_bbox","`","(","dict",")",":","A","dictionary","of","bbox","loss","components",".","-","`","rois","`","(","Tensor",")",":","RoIs","with","the","shape","(","n",",","5",")","where","the","first","column","indicates","batch","id","of","each","RoI",".","-","`","bbox_targets","`","(","tuple",")",":","Ground","truth","for","proposals","in","a","single","image",".","Containing","the","following","list","of","Tensors",":","(","labels",",","label_weights",",","bbox_targets",",","bbox_weights",")"]
code: def bbox_loss(
      self,
      stage: int,
      x: Tuple[Tensor],
      sampling_results: List[SamplingResult],
  ) -> dict:
      """Run forward function and calculate loss for box head in training.
  
      Args:
          stage (int): The current stage in Cascade RoI Head.
          x (tuple[Tensor]): List of multi-level img features.
          sampling_results (list["obj:`SamplingResult`]): Sampling results.
  
      Returns:
          dict: Usually returns a dictionary with keys:
  
              - `cls_score` (Tensor): Classification scores.
              - `bbox_pred` (Tensor): Box energies / deltas.
              - `bbox_feats` (Tensor): Extract bbox RoI features.
              - `loss_bbox` (dict): A dictionary of bbox loss components.
              - `rois` (Tensor): RoIs with the shape (n, 5) where the first
                column indicates batch id of each RoI.
              - `bbox_targets` (tuple):  Ground truth for proposals in a
                single image. Containing the following list of Tensors:
                (labels, label_weights, bbox_targets, bbox_weights)
      """
      bbox_head = self.bbox_head[stage]
      rois = bbox2roi([res.priors for res in sampling_results])
      bbox_results = self._bbox_forward(stage, x, rois)
      bbox_results.update(rois=rois)
  
      bbox_loss_and_target = bbox_head.loss_and_target(
          cls_score=bbox_results["cls_score"],
          bbox_pred=bbox_results["bbox_pred"],
          rois=rois,
          sampling_results=sampling_results,
          rcnn_train_cfg=self.train_cfg[stage],
      )
      bbox_results.update(bbox_loss_and_target)
  
      return bbox_results
  
imports: from typing import List, Sequence, Tuple, Union
  import torch
  import torch.nn
  from mmengine.model import ModuleList
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.task_modules.samplers import SamplingResult
  from mmdet.models.test_time_augs import merge_aug_masks
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox2roi, get_box_tensor
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptConfigType, OptMultiConfig
  from ..utils.misc import empty_instances, unpack_gt_instances
  from .base_roi_head import BaseRoIHead
label_desc: Use image node_id 6 for calling the CascadeRoIHead obj's underlying member method code with example usage: obj.bbox_loss(stage, x, sampling_results) and returns: bbox_results