class_docstr: Base class for DenseHeads.
  
  1. The ``init_weights`` method is used to initialize densehead's
  model parameters. After detector initialization, ``init_weights``
  is triggered when ``detector.init_weights()`` is called externally.
  
  2. The ``loss`` method is used to calculate the loss of densehead,
  which includes two steps: (1) the densehead model performs forward
  propagation to obtain the feature maps (2) The ``loss_by_feat`` method
  is called based on the feature maps to calculate the loss.
  
  .. code:: text
  
  loss(): forward() -> loss_by_feat()
  
  3. The ``predict`` method is used to predict detection results,
  which includes two steps: (1) the densehead model performs forward
  propagation to obtain the feature maps (2) The ``predict_by_feat`` method
  is called based on the feature maps to predict detection results including
  post-processing.
  
  .. code:: text
  
  predict(): forward() -> predict_by_feat()
  
  4. The ``loss_and_predict`` method is used to return loss and detection
  results at the same time. It will call densehead's ``forward``,
  ``loss_by_feat`` and ``predict_by_feat`` methods in order.  If one-stage is
  used as RPN, the densehead needs to return both losses and predictions.
  This predictions is used as the proposal of roihead.
  
  .. code:: text
  
  loss_and_predict(): forward() -> loss_by_feat() -> predict_by_feat()
class_docstr_tok: ["Base","class","for","DenseHeads",".","1",".","The","``","init_weights","``","method","is","used","to","initialize","densehead's","model","parameters",".","After","detector","initialization",",","``","init_weights","``","is","triggered","when","``","detector.init_weights","(",")","``","is","called","externally",".","2",".","The","``","loss","``","method","is","used","to","calculate","the","loss","of","densehead",",","which","includes","two","steps",":","(","1",")","the","densehead","model","performs","forward","propagation","to","obtain","the","feature","maps","(","2",")","The","``","loss_by_feat","``","method","is","called","based","on","the","feature","maps","to","calculate","the","loss",".","..","code",":",":","text","loss","(",")",":","forward","(",")","-",">","loss_by_feat","(",")","3",".","The","``","predict","``","method","is","used","to","predict","detection","results",",","which","includes","two","steps",":","(","1",")","the","densehead","model","performs","forward","propagation","to","obtain","the","feature","maps","(","2",")","The","``","predict_by_feat","``","method","is","called","based","on","the","feature","maps","to","predict","detection","results","including","post-processing",".","..","code",":",":","text","predict","(",")",":","forward","(",")","-",">","predict_by_feat","(",")","4",".","The","``","loss_and_predict","``","method","is","used","to","return","loss","and","detection","results","at","the","same","time",".","It","will","call","densehead","'s","``","forward","``",",","``","loss_by_feat","``","and","``","predict_by_feat","``","methods","in","order",".","If","one-stage","is","used","as","RPN",",","the","densehead","needs","to","return","both","losses","and","predictions",".","This","predictions","is","used","as","the","proposal","of","roihead",".","..","code",":",":","text","loss_and_predict","(",")",":","forward","(",")","-",">","loss_by_feat","(",")","-",">","predict_by_feat","(",")"]
docstr: bbox post-processing method.
  
  The boxes would be rescaled to the original image scale and do
  the nms operation. Usually `with_nms` is False is used for aug test.
  
  Args:
      results (:obj:`InstaceData`): Detection instance results,
          each item has shape (num_bboxes, ).
      cfg (ConfigDict): Test / postprocessing configuration,
          if None, test_cfg would be used.
      rescale (bool): If True, return boxes in original image space.
          Default to False.
      with_nms (bool): If True, do nms before return boxes.
          Default to True.
      img_meta (dict, optional): Image meta info. Defaults to None.
  
  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: ["bbox","post-processing","method",".","The","boxes","would","be","rescaled","to","the","original","image","scale","and","do","the","nms","operation",".","Usually","`","with_nms","`","is","False","is","used","for","aug","test",".","Args",":","results","(",":","obj",":","`","InstaceData","`",")",":","Detection","instance","results",",","each","item","has","shape","(","num_bboxes",",",")",".","cfg","(","ConfigDict",")",":","Test","\/","postprocessing","configuration",",","if","None",",","test_cfg","would","be","used",".","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Default","to","False",".","with_nms","(","bool",")",":","If","True",",","do","nms","before","return","boxes",".","Default","to","True",".","img_meta","(","dict",",","optional",")",":","Image","meta","info",".","Defaults","to","None",".","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 _bbox_post_process(
      self,
      results: InstanceData,
      cfg: ConfigDict,
      rescale: bool = False,
      with_nms: bool = True,
      img_meta: Optional[dict] = None,
  ) -> InstanceData:
      """bbox post-processing method.
  
      The boxes would be rescaled to the original image scale and do
      the nms operation. Usually `with_nms` is False is used for aug test.
  
      Args:
          results (:obj:`InstaceData`): Detection instance results,
              each item has shape (num_bboxes, ).
          cfg (ConfigDict): Test / postprocessing configuration,
              if None, test_cfg would be used.
          rescale (bool): If True, return boxes in original image space.
              Default to False.
          with_nms (bool): If True, do nms before return boxes.
              Default to True.
          img_meta (dict, optional): Image meta info. Defaults to None.
  
      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).
      """
      if rescale:
          assert img_meta.get("scale_factor") is not None
          scale_factor = [1 / s for s in img_meta["scale_factor"]]
          results.bboxes = scale_boxes(results.bboxes, scale_factor)
  
      if hasattr(results, "score_factors"):
          # TODO: Add sqrt operation in order to be consistent with
          #  the paper.
          score_factors = results.pop("score_factors")
          results.scores = results.scores * score_factors
  
      # filter small size bboxes
      if cfg.get("min_bbox_size", -1) >= 0:
          w, h = get_box_wh(results.bboxes)
          valid_mask = (w > cfg.min_bbox_size) & (h > cfg.min_bbox_size)
          if not valid_mask.all():
              results = results[valid_mask]
  
      # TODO: deal with `with_nms` and `nms_cfg=None` in test_cfg
      if with_nms and results.bboxes.numel() > 0:
          bboxes = get_box_tensor(results.bboxes)
          det_bboxes, keep_idxs = batched_nms(
              bboxes, results.scores, results.labels, cfg.nms
          )
          results = results[keep_idxs]
          # some nms would reweight the score, such as softnms
          results.scores = det_bboxes[:, -1]
          results = results[: cfg.max_per_img]
  
      return results
  
imports: import copy
  from abc import ABCMeta, abstractmethod
  from inspect import signature
  from typing import List, Optional, Tuple
  import torch
  from mmcv.ops import batched_nms
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModule, constant_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import cat_boxes, get_box_tensor, get_box_wh, scale_boxes
  from mmdet.utils import InstanceList, OptMultiConfig
  from ..test_time_augs import merge_aug_results
  from ..utils import filter_scores_and_topk, select_single_mlvl, unpack_gt_instances
label_desc: Use image node_id 10 for calling the BaseDenseHead obj's underlying member method code with example usage: obj._bbox_post_process(results, cfg, rescale, with_nms, img_meta) and returns: results