docstr: Perform forward propagation of the bbox head and predict detection
  results on the features of the upstream network.
  
  Args:
      x (tuple[Tensor]): Feature maps of all scale level.
      batch_img_metas (list[dict]): List of image information.
      rpn_results_list (list[:obj:`InstanceData`]): List of region
          proposals.
      rcnn_test_cfg (obj:`ConfigDict`): `test_cfg` of R-CNN.
      rescale (bool): If True, return boxes in original image space.
          Defaults to False.
  
  Returns:
      list[:obj:`InstanceData`]: Detection results of each image
      after the post process.
      Each item usually contains following keys.
  
          - scores (Tensor): Classification scores, has a shape
            (num_instance, )
          - labels (Tensor): Labels of bboxes, has a shape
            (num_instances, ).
          - bboxes (Tensor): Has a shape (num_instances, 4),
            the last dimension 4 arrange as (x1, y1, x2, y2).
docstr_tok: ["Perform","forward","propagation","of","the","bbox","head","and","predict","detection","results","on","the","features","of","the","upstream","network",".","Args",":","x","(","tuple","[","Tensor","]",")",":","Feature","maps","of","all","scale","level",".","batch_img_metas","(","list","[","dict","]",")",":","List","of","image","information",".","rpn_results_list","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","List","of","region","proposals",".","rcnn_test_cfg","(","obj",":","`","ConfigDict","`",")",":","`","test_cfg","`","of","R-CNN",".","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Defaults","to","False",".","Returns",":","list","[",":","obj",":","`","InstanceData","`","]",":","Detection","results","of","each","image","after","the","post","process",".","Each","item","usually","contains","following","keys",".","-","scores","(","Tensor",")",":","Classification","scores",",","has","a","shape","(","num_instance",",",")","-","labels","(","Tensor",")",":","Labels","of","bboxes",",","has","a","shape","(","num_instances",",",")",".","-","bboxes","(","Tensor",")",":","Has","a","shape","(","num_instances",",","4",")",",","the","last","dimension","4","arrange","as","(","x1",",","y1",",","x2",",","y2",")","."]
code: def predict_bbox(
      self,
      x: Tuple[Tensor],
      batch_img_metas: List[dict],
      rpn_results_list: InstanceList,
      rcnn_test_cfg: ConfigType,
      rescale: bool = False,
      **kwargs,
  ) -> InstanceList:
      """Perform forward propagation of the bbox head and predict detection
      results on the features of the upstream network.
  
      Args:
          x (tuple[Tensor]): Feature maps of all scale level.
          batch_img_metas (list[dict]): List of image information.
          rpn_results_list (list[:obj:`InstanceData`]): List of region
              proposals.
          rcnn_test_cfg (obj:`ConfigDict`): `test_cfg` of R-CNN.
          rescale (bool): If True, return boxes in original image space.
              Defaults to False.
  
      Returns:
          list[:obj:`InstanceData`]: Detection results of each image
          after the post process.
          Each item usually contains following keys.
  
              - scores (Tensor): Classification scores, has a shape
                (num_instance, )
              - labels (Tensor): Labels of bboxes, has a shape
                (num_instances, ).
              - bboxes (Tensor): Has a shape (num_instances, 4),
                the last dimension 4 arrange as (x1, y1, x2, y2).
      """
      proposals = [res.bboxes for res in rpn_results_list]
      proposal_scores = [res.scores for res in rpn_results_list]
      num_proposals_per_img = tuple(len(p) for p in proposals)
      rois = bbox2roi(proposals)
  
      if rois.shape[0] == 0:
          return empty_instances(
              batch_img_metas,
              rois.device,
              task_type="bbox",
              box_type=self.bbox_head[-1].predict_box_type,
              num_classes=self.bbox_head[-1].num_classes,
              score_per_cls=rcnn_test_cfg is None,
          )
      # rois aligned
      rois, cls_scores, bbox_preds = self._refine_roi(
          x=x,
          rois=rois,
          batch_img_metas=batch_img_metas,
          num_proposals_per_img=num_proposals_per_img,
          **kwargs,
      )
  
      # score reweighting in centernet2
      cls_scores = [
          (s * ps[:, None]) ** 0.5
          for s, ps in zip(cls_scores, proposal_scores)
      ]
      cls_scores = [
          s * (s == s[:, :-1].max(dim=1)[0][:, None]).float()
          for s in cls_scores
      ]
  
      # fast_rcnn_inference
      results_list = self.bbox_head[-1].predict_by_feat(
          rois=rois,
          cls_scores=cls_scores,
          bbox_preds=bbox_preds,
          batch_img_metas=batch_img_metas,
          rescale=rescale,
          rcnn_test_cfg=rcnn_test_cfg,
      )
      return results_list
  
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 4 for calling the DeticRoIHead obj's underlying member method code with example usage: obj.predict_bbox(x, batch_img_metas, rpn_results_list, rcnn_test_cfg, rescale) and returns: results_list, empty_instances