class_docstr: Stage of CascadeRPNHead.
  
  Args:
      in_channels (int): Number of channels in the input feature map.
      anchor_generator (:obj:`ConfigDict` or dict): anchor generator config.
      adapt_cfg (:obj:`ConfigDict` or dict): adaptation config.
      bridged_feature (bool): whether update rpn feature. Defaults to False.
      with_cls (bool): whether use classification branch. Defaults to True.
      init_cfg :obj:`ConfigDict` or list[:obj:`ConfigDict`] or dict or
          list[dict], optional): Initialization config dict.
          Defaults to None.
class_docstr_tok: ["Stage","of","CascadeRPNHead",".","Args",":","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","anchor_generator","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","anchor","generator","config",".","adapt_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","adaptation","config",".","bridged_feature","(","bool",")",":","whether","update","rpn","feature",".","Defaults","to","False",".","with_cls","(","bool",")",":","whether","use","classification","branch",".","Defaults","to","True",".","init_cfg",":","obj",":","`","ConfigDict","`","or","list","[",":","obj",":","`","ConfigDict","`","]","or","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict",".","Defaults","to","None","."]
docstr: Transform outputs of a single image into bbox predictions.
  
  Args:
      cls_scores (list[Tensor]): Box scores from all scale
          levels of a single image, each item has shape
          (num_anchors * num_classes, H, W).
      bbox_preds (list[Tensor]): Box energies / deltas from
          all scale levels of a single image, each item has
          shape (num_anchors * 4, H, W).
      mlvl_anchors (list[Tensor]): Box reference from all scale
          levels of a single image, each item has shape
          (num_total_anchors, 4).
      img_shape (tuple[int]): Shape of the input image,
          (height, width, 3).
      scale_factor (ndarray): Scale factor of the image arange as
          (w_scale, h_scale, w_scale, h_scale).
      cfg (:obj:`ConfigDict`): Test / postprocessing configuration,
          if None, test_cfg would be used.
      rescale (bool): If True, return boxes in original image space.
          Defaults to False.
  
  Returns:
      :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: ["Transform","outputs","of","a","single","image","into","bbox","predictions",".","Args",":","cls_scores","(","list","[","Tensor","]",")",":","Box","scores","from","all","scale","levels","of","a","single","image",",","each","item","has","shape","(","num_anchors","*","num_classes",",","H",",","W",")",".","bbox_preds","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","from","all","scale","levels","of","a","single","image",",","each","item","has","shape","(","num_anchors","*","4",",","H",",","W",")",".","mlvl_anchors","(","list","[","Tensor","]",")",":","Box","reference","from","all","scale","levels","of","a","single","image",",","each","item","has","shape","(","num_total_anchors",",","4",")",".","img_shape","(","tuple","[","int","]",")",":","Shape","of","the","input","image",",","(","height",",","width",",","3",")",".","scale_factor","(","ndarray",")",":","Scale","factor","of","the","image","arange","as","(","w_scale",",","h_scale",",","w_scale",",","h_scale",")",".","cfg","(",":","obj",":","`","ConfigDict","`",")",":","Test","\/","postprocessing","configuration",",","if","None",",","test_cfg","would","be","used",".","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Defaults","to","False",".","Returns",":",":","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_by_feat_single(
      self,
      cls_scores: List[Tensor],
      bbox_preds: List[Tensor],
      mlvl_anchors: List[Tensor],
      img_meta: dict,
      cfg: ConfigDict,
      rescale: bool = False,
  ) -> InstanceData:
      """Transform outputs of a single image into bbox predictions.
  
      Args:
          cls_scores (list[Tensor]): Box scores from all scale
              levels of a single image, each item has shape
              (num_anchors * num_classes, H, W).
          bbox_preds (list[Tensor]): Box energies / deltas from
              all scale levels of a single image, each item has
              shape (num_anchors * 4, H, W).
          mlvl_anchors (list[Tensor]): Box reference from all scale
              levels of a single image, each item has shape
              (num_total_anchors, 4).
          img_shape (tuple[int]): Shape of the input image,
              (height, width, 3).
          scale_factor (ndarray): Scale factor of the image arange as
              (w_scale, h_scale, w_scale, h_scale).
          cfg (:obj:`ConfigDict`): Test / postprocessing configuration,
              if None, test_cfg would be used.
          rescale (bool): If True, return boxes in original image space.
              Defaults to False.
  
      Returns:
          :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).
      """
      cfg = self.test_cfg if cfg is None else cfg
      cfg = copy.deepcopy(cfg)
      # bboxes from different level should be independent during NMS,
      # level_ids are used as labels for batched NMS to separate them
      level_ids = []
      mlvl_scores = []
      mlvl_bbox_preds = []
      mlvl_valid_anchors = []
      nms_pre = cfg.get("nms_pre", -1)
      for idx in range(len(cls_scores)):
          rpn_cls_score = cls_scores[idx]
          rpn_bbox_pred = bbox_preds[idx]
          assert rpn_cls_score.size()[-2:] == rpn_bbox_pred.size()[-2:]
          rpn_cls_score = rpn_cls_score.permute(1, 2, 0)
          if self.use_sigmoid_cls:
              rpn_cls_score = rpn_cls_score.reshape(-1)
              scores = rpn_cls_score.sigmoid()
          else:
              rpn_cls_score = rpn_cls_score.reshape(-1, 2)
              # We set FG labels to [0, num_class-1] and BG label to
              # num_class in RPN head since mmdet v2.5, which is unified to
              # be consistent with other head since mmdet v2.0. In mmdet v2.0
              # to v2.4 we keep BG label as 0 and FG label as 1 in rpn head.
              scores = rpn_cls_score.softmax(dim=1)[:, 0]
          rpn_bbox_pred = rpn_bbox_pred.permute(1, 2, 0).reshape(-1, 4)
          anchors = mlvl_anchors[idx]
  
          if 0 < nms_pre < scores.shape[0]:
              # sort is faster than topk
              # _, topk_inds = scores.topk(cfg.nms_pre)
              ranked_scores, rank_inds = scores.sort(descending=True)
              topk_inds = rank_inds[:nms_pre]
              scores = ranked_scores[:nms_pre]
              rpn_bbox_pred = rpn_bbox_pred[topk_inds, :]
              anchors = anchors[topk_inds, :]
          mlvl_scores.append(scores)
          mlvl_bbox_preds.append(rpn_bbox_pred)
          mlvl_valid_anchors.append(anchors)
          level_ids.append(
              scores.new_full((scores.size(0),), idx, dtype=torch.long)
          )
  
      anchors = torch.cat(mlvl_valid_anchors)
      rpn_bbox_pred = torch.cat(mlvl_bbox_preds)
      bboxes = self.bbox_coder.decode(
          anchors, rpn_bbox_pred, max_shape=img_meta["img_shape"]
      )
  
      proposals = InstanceData()
      proposals.bboxes = bboxes
      proposals.scores = torch.cat(mlvl_scores)
      proposals.level_ids = torch.cat(level_ids)
  
      return self._bbox_post_process(
          results=proposals, cfg=cfg, rescale=rescale, img_meta=img_meta
      )
  
imports: from __future__ import division
  import copy
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  import torch.nn
  from mmcv.ops import DeformConv2d
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModule, ModuleList
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures import SampleList
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptInstanceList, OptMultiConfig
  from ..task_modules.assigners import RegionAssigner
  from ..task_modules.samplers import PseudoSampler
  from ..utils import images_to_levels, multi_apply, select_single_mlvl, unpack_gt_instances
  from .base_dense_head import BaseDenseHead
  from .rpn_head import RPNHead
label_desc: Use image node_id 12 for calling the StageCascadeRPNHead obj's underlying member method code with example usage: obj._predict_by_feat_single(cls_scores, bbox_preds, mlvl_anchors, img_meta, cfg, rescale) and returns: self