docstr: Box head forward function used in both training and testing.
  
  Args:
      stage (int): The current stage in Cascade RoI Head.
      x (tuple[Tensor]): List of multi-level img features.
      rois (Tensor): RoIs with the shape (n, 5) where the first
          column indicates batch id of each RoI.
  
  Returns:
       dict[str, Tensor]: Usually returns a dictionary with keys:
  
          - `cls_score` (Tensor): Classification scores.
          - `bbox_pred` (Tensor): Box energies / deltas.
          - `bbox_feats` (Tensor): Extract bbox RoI features.
docstr_tok: ["Box","head","forward","function","used","in","both","training","and","testing",".","Args",":","stage","(","int",")",":","The","current","stage","in","Cascade","RoI","Head",".","x","(","tuple","[","Tensor","]",")",":","List","of","multi-level","img","features",".","rois","(","Tensor",")",":","RoIs","with","the","shape","(","n",",","5",")","where","the","first","column","indicates","batch","id","of","each","RoI",".","Returns",":","dict","[","str",",","Tensor","]",":","Usually","returns","a","dictionary","with","keys",":","-","`","cls_score","`","(","Tensor",")",":","Classification","scores",".","-","`","bbox_pred","`","(","Tensor",")",":","Box","energies","\/","deltas",".","-","`","bbox_feats","`","(","Tensor",")",":","Extract","bbox","RoI","features","."]
code: def _bbox_forward(
      self, stage: int, x: Tuple[Tensor], rois: Tensor
  ) -> dict:
      """Box head forward function used in both training and testing.
  
      Args:
          stage (int): The current stage in Cascade RoI Head.
          x (tuple[Tensor]): List of multi-level img features.
          rois (Tensor): RoIs with the shape (n, 5) where the first
              column indicates batch id of each RoI.
  
      Returns:
           dict[str, Tensor]: Usually returns a dictionary with keys:
  
              - `cls_score` (Tensor): Classification scores.
              - `bbox_pred` (Tensor): Box energies / deltas.
              - `bbox_feats` (Tensor): Extract bbox RoI features.
      """
      bbox_roi_extractor = self.bbox_roi_extractor[stage]
      bbox_head = self.bbox_head[stage]
      bbox_feats = bbox_roi_extractor(
          x[: bbox_roi_extractor.num_inputs], rois
      )
      # do not support caffe_c4 model anymore
      cls_score, bbox_pred = bbox_head(bbox_feats)
  
      bbox_results = dict(
          cls_score=cls_score,
          bbox_pred=bbox_pred,
          bbox_feats=bbox_feats,
      )
      return bbox_results
  
imports: from typing import List, Sequence, Tuple
  import torch
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.roi_heads import CascadeRoIHead
  from mmdet.models.task_modules.samplers import SamplingResult
  from mmdet.models.test_time_augs import merge_aug_masks
  from mmdet.models.utils.misc import empty_instances
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox2roi, get_box_tensor
  from mmdet.utils import ConfigType, InstanceList, MultiConfig
label_desc: Use image node_id 3 for calling the DeticRoIHead obj's underlying member method code with example usage: obj._bbox_forward(stage, x, rois) and returns: bbox_results