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: 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.
      semantic_feat (Tensor, optional): Semantic feature. Defaults to
          None.
  
  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",".","semantic_feat","(","Tensor",",","optional",")",":","Semantic","feature",".","Defaults","to","None",".","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,
      semantic_feat: Optional[Tensor] = None,
  ) -> Dict[str, Tensor]:
      """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.
          semantic_feat (Tensor, optional): Semantic feature. Defaults to
              None.
  
      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
      )
      if self.with_semantic and "bbox" in self.semantic_fusion:
          bbox_semantic_feat = self.semantic_roi_extractor(
              [semantic_feat], rois
          )
          if bbox_semantic_feat.shape[-2:] != bbox_feats.shape[-2:]:
              bbox_semantic_feat = adaptive_avg_pool2d(
                  bbox_semantic_feat, bbox_feats.shape[-2:]
              )
          bbox_feats += bbox_semantic_feat
      cls_score, bbox_pred = bbox_head(bbox_feats)
  
      bbox_results = dict(cls_score=cls_score, bbox_pred=bbox_pred)
      return bbox_results
  
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 3 for calling the HybridTaskCascadeRoIHead obj's underlying member method code with example usage: obj._bbox_forward(stage, x, rois, semantic_feat) and returns: bbox_results