class_docstr: Implementation of RPN head.
  
  Args:
      in_channels (int): Number of channels in the input feature map.
      num_classes (int): Number of categories excluding the background
          category. Defaults to 1.
      init_cfg (:obj:`ConfigDict` or list[:obj:`ConfigDict`] or dict or             list[dict]): Initialization config dict.
      num_convs (int): Number of convolution layers in the head.
          Defaults to 1.
docstr: Transform a single image's features extracted from the head into
  bbox results.
  
  Args:
      cls_score_list (list[Tensor]): Box scores from all scale
          levels of a single image, each item has shape
          (num_priors * num_classes, H, W).
      bbox_pred_list (list[Tensor]): Box energies / deltas from
          all scale levels of a single image, each item has shape
          (num_priors * 4, H, W).
      score_factor_list (list[Tensor]): Be compatible with
          BaseDenseHead. Not used in RPNHead.
      mlvl_priors (list[Tensor]): Each element in the list is
          the priors of a single level in feature pyramid. In all
          anchor-based methods, it has shape (num_priors, 4). In
          all anchor-free methods, it has shape (num_priors, 2)
          when `with_stride=True`, otherwise it still has shape
          (num_priors, 4).
      img_meta (dict): Image meta info.
      cfg (ConfigDict, optional): 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","a","single","image","'s","features","extracted","from","the","head","into","bbox","results",".","Args",":","cls_score_list","(","list","[","Tensor","]",")",":","Box","scores","from","all","scale","levels","of","a","single","image",",","each","item","has","shape","(","num_priors","*","num_classes",",","H",",","W",")",".","bbox_pred_list","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","from","all","scale","levels","of","a","single","image",",","each","item","has","shape","(","num_priors","*","4",",","H",",","W",")",".","score_factor_list","(","list","[","Tensor","]",")",":","Be","compatible","with","BaseDenseHead",".","Not","used","in","RPNHead",".","mlvl_priors","(","list","[","Tensor","]",")",":","Each","element","in","the","list","is","the","priors","of","a","single","level","in","feature","pyramid",".","In","all","anchor-based","methods",",","it","has","shape","(","num_priors",",","4",")",".","In","all","anchor-free","methods",",","it","has","shape","(","num_priors",",","2",")","when","`","with_stride=True","`",",","otherwise","it","still","has","shape","(","num_priors",",","4",")",".","img_meta","(","dict",")",":","Image","meta","info",".","cfg","(","ConfigDict",",","optional",")",":","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_score_list: List[Tensor],
      bbox_pred_list: List[Tensor],
      score_factor_list: List[Tensor],
      mlvl_priors: List[Tensor],
      img_meta: dict,
      cfg: ConfigDict,
      rescale: bool = False,
      with_nms: bool = True,
  ) -> InstanceData:
      """Transform a single image's features extracted from the head into
      bbox results.
  
      Args:
          cls_score_list (list[Tensor]): Box scores from all scale
              levels of a single image, each item has shape
              (num_priors * num_classes, H, W).
          bbox_pred_list (list[Tensor]): Box energies / deltas from
              all scale levels of a single image, each item has shape
              (num_priors * 4, H, W).
          score_factor_list (list[Tensor]): Be compatible with
              BaseDenseHead. Not used in RPNHead.
          mlvl_priors (list[Tensor]): Each element in the list is
              the priors of a single level in feature pyramid. In all
              anchor-based methods, it has shape (num_priors, 4). In
              all anchor-free methods, it has shape (num_priors, 2)
              when `with_stride=True`, otherwise it still has shape
              (num_priors, 4).
          img_meta (dict): Image meta info.
          cfg (ConfigDict, optional): 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)
      img_shape = img_meta["img_shape"]
      nms_pre = cfg.get("nms_pre", -1)
  
      mlvl_bbox_preds = []
      mlvl_valid_priors = []
      mlvl_scores = []
      level_ids = []
      for level_idx, (cls_score, bbox_pred, priors) in enumerate(
          zip(cls_score_list, bbox_pred_list, mlvl_priors)
      ):
          assert cls_score.size()[-2:] == bbox_pred.size()[-2:]
  
          reg_dim = self.bbox_coder.encode_size
          bbox_pred = bbox_pred.permute(1, 2, 0).reshape(-1, reg_dim)
          cls_score = cls_score.permute(1, 2, 0).reshape(
              -1, self.cls_out_channels
          )
          if self.use_sigmoid_cls:
              scores = cls_score.sigmoid()
          else:
              # remind that we set FG labels to [0] since mmdet v2.0
              # BG cat_id: 1
              scores = cls_score.softmax(-1)[:, :-1]
  
          scores = torch.squeeze(scores)
          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]
              bbox_pred = bbox_pred[topk_inds, :]
              priors = priors[topk_inds]
  
          mlvl_bbox_preds.append(bbox_pred)
          mlvl_valid_priors.append(priors)
          mlvl_scores.append(scores)
  
          # use level id to implement the separate level nms
          level_ids.append(
              scores.new_full(
                  (scores.size(0),), level_idx, dtype=torch.long
              )
          )
  
      bbox_pred = torch.cat(mlvl_bbox_preds)
      priors = cat_boxes(mlvl_valid_priors)
      bboxes = self.bbox_coder.decode(
          priors, bbox_pred, max_shape=img_shape
      )
  
      results = InstanceData()
      results.bboxes = bboxes
      results.scores = torch.cat(mlvl_scores)
      results.level_ids = torch.cat(level_ids)
  
      return self._bbox_post_process(
          results=results, cfg=cfg, rescale=rescale, img_meta=img_meta
      )
  
imports: import copy
  from typing import List, Optional, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule
  from mmcv.ops import batched_nms
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import cat_boxes, empty_box_as, get_box_tensor, get_box_wh, scale_boxes
  from mmdet.utils import InstanceList, MultiConfig, OptInstanceList
  from .anchor_head import AnchorHead
label_desc: Use image node_id 5 for calling the RPNHead obj's underlying member method code with example usage: obj._predict_by_feat_single(cls_score_list, bbox_pred_list, score_factor_list, mlvl_priors, img_meta, cfg, rescale, with_nms) and returns: self