class_docstr: CenterNetUpdateHead is an improved version of CenterNet in CenterNet2.
  
  Paper link `<https://arxiv.org/abs/2103.07461>`_.
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channel in the input feature map.
      regress_ranges (Sequence[Tuple[int, int]]): Regress range of multiple
          level points.
      hm_min_radius (int): Heatmap target minimum radius of cls branch.
          Defaults to 4.
      hm_min_overlap (float): Heatmap target minimum overlap of cls branch.
          Defaults to 0.8.
      more_pos_thresh (float): The filtering threshold when the cls branch
          adds more positive samples. Defaults to 0.2.
      more_pos_topk (int): The maximum number of additional positive samples
          added to each gt. Defaults to 9.
      soft_weight_on_reg (bool): Whether to use the soft target of the
          cls branch as the soft weight of the bbox branch.
          Defaults to False.
      loss_cls (:obj:`ConfigDict` or dict): Config of cls loss. Defaults to
          dict(type='GaussianFocalLoss', loss_weight=1.0)
      loss_bbox (:obj:`ConfigDict` or dict): Config of bbox loss. Defaults to
           dict(type='GIoULoss', loss_weight=2.0).
      norm_cfg (:obj:`ConfigDict` or dict, optional): dictionary to construct
          and config norm layer.  Defaults to
          ``norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)``.
      train_cfg (:obj:`ConfigDict` or dict, optional): Training config.
          Unused in CenterNet. Reserved for compatibility with
          SingleStageDetector.
      test_cfg (:obj:`ConfigDict` or dict, optional): Testing config
          of CenterNet.
class_docstr_tok: ["CenterNetUpdateHead","is","an","improved","version","of","CenterNet","in","CenterNet2",".","Paper","link","`","<","https",":","\/\/arxiv.org\/abs\/2103.07461",">","`","_",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channel","in","the","input","feature","map",".","regress_ranges","(","Sequence","[","Tuple","[","int",",","int","]","]",")",":","Regress","range","of","multiple","level","points",".","hm_min_radius","(","int",")",":","Heatmap","target","minimum","radius","of","cls","branch",".","Defaults","to","4.","hm_min_overlap","(","float",")",":","Heatmap","target","minimum","overlap","of","cls","branch",".","Defaults","to","0.8.","more_pos_thresh","(","float",")",":","The","filtering","threshold","when","the","cls","branch","adds","more","positive","samples",".","Defaults","to","0.2.","more_pos_topk","(","int",")",":","The","maximum","number","of","additional","positive","samples","added","to","each","gt",".","Defaults","to","9.","soft_weight_on_reg","(","bool",")",":","Whether","to","use","the","soft","target","of","the","cls","branch","as","the","soft","weight","of","the","bbox","branch",".","Defaults","to","False",".","loss_cls","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","cls","loss",".","Defaults","to","dict","(","type='GaussianFocalLoss","'",",","loss_weight=1.0",")","loss_bbox","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","bbox","loss",".","Defaults","to","dict","(","type='GIoULoss","'",",","loss_weight=2.0",")",".","norm_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","dictionary","to","construct","and","config","norm","layer",".","Defaults","to","``","norm_cfg=dict","(","type='GN","'",",","num_groups=32",",","requires_grad=True",")","``",".","train_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Training","config",".","Unused","in","CenterNet",".","Reserved","for","compatibility","with","SingleStageDetector",".","test_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Testing","config","of","CenterNet","."]
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]): Score factor from all scale
          levels of a single image, each item has shape
          (num_priors * 1, H, W).
      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 (mmengine.Config): Test / postprocessing configuration,
          if None, test_cfg would be used.
      rescale (bool): If True, return boxes in original image space.
          Defaults to False.
      with_nms (bool): If True, do nms before return boxes.
          Defaults to True.
  
  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","]",")",":","Score","factor","from","all","scale","levels","of","a","single","image",",","each","item","has","shape","(","num_priors","*","1",",","H",",","W",")",".","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","(","mmengine.Config",")",":","Test","\/","postprocessing","configuration",",","if","None",",","test_cfg","would","be","used",".","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Defaults","to","False",".","with_nms","(","bool",")",":","If","True",",","do","nms","before","return","boxes",".","Defaults","to","True",".","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]): Score factor from all scale
              levels of a single image, each item has shape
              (num_priors * 1, H, W).
          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 (mmengine.Config): Test / postprocessing configuration,
              if None, test_cfg would be used.
          rescale (bool): If True, return boxes in original image space.
              Defaults to False.
          with_nms (bool): If True, do nms before return boxes.
              Defaults to True.
  
      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)
      nms_pre = cfg.get("nms_pre", -1)
  
      mlvl_bbox_preds = []
      mlvl_valid_priors = []
      mlvl_scores = []
      mlvl_labels = []
  
      for level_idx, (
          cls_score,
          bbox_pred,
          score_factor,
          priors,
      ) in enumerate(
          zip(
              cls_score_list,
              bbox_pred_list,
              score_factor_list,
              mlvl_priors,
          )
      ):
          assert cls_score.size()[-2:] == bbox_pred.size()[-2:]
  
          bbox_pred = bbox_pred * self.strides[level_idx]
  
          dim = self.bbox_coder.encode_size
          bbox_pred = bbox_pred.permute(1, 2, 0).reshape(-1, dim)
          cls_score = cls_score.permute(1, 2, 0).reshape(
              -1, self.cls_out_channels
          )
          heatmap = cls_score.sigmoid()
          score_thr = cfg.get("score_thr", 0)
  
          candidate_inds = heatmap > score_thr  # 0.05
          pre_nms_top_n = candidate_inds.sum()  # N
          pre_nms_top_n = pre_nms_top_n.clamp(max=nms_pre)  # N
  
          heatmap = heatmap[candidate_inds]  # n
  
          candidate_nonzeros = candidate_inds.nonzero()  # n
          box_loc = candidate_nonzeros[:, 0]  # n
          labels = candidate_nonzeros[:, 1]  # n
  
          bbox_pred = bbox_pred[box_loc]  # n x 4
          per_grids = priors[box_loc]  # n x 2
  
          if candidate_inds.sum().item() > pre_nms_top_n.item():
              heatmap, top_k_indices = heatmap.topk(
                  pre_nms_top_n, sorted=False
              )
              labels = labels[top_k_indices]
              bbox_pred = bbox_pred[top_k_indices]
              per_grids = per_grids[top_k_indices]
  
          bboxes = torch.stack(
              [
                  per_grids[:, 0] - bbox_pred[:, 0],
                  per_grids[:, 1] - bbox_pred[:, 1],
                  per_grids[:, 0] + bbox_pred[:, 2],
                  per_grids[:, 1] + bbox_pred[:, 3],
              ],
              dim=1,
          )  # n x 4
  
          # avoid invalid boxes in RoI heads
          bboxes[:, 2] = torch.max(bboxes[:, 2], bboxes[:, 0] + 0.01)
          bboxes[:, 3] = torch.max(bboxes[:, 3], bboxes[:, 1] + 0.01)
  
          # bboxes = self.bbox_coder.decode(per_grids, bbox_pred)
          # # avoid invalid boxes in RoI heads
          # bboxes[:, 2] = torch.max(bboxes[:, 2], bboxes[:, 0] + 0.01)
          # bboxes[:, 3] = torch.max(bboxes[:, 3], bboxes[:, 1] + 0.01)
  
          mlvl_bbox_preds.append(bboxes)
          mlvl_valid_priors.append(priors)
          mlvl_scores.append(torch.sqrt(heatmap))
          mlvl_labels.append(labels)
  
      results = InstanceData()
      results.bboxes = torch.cat(mlvl_bbox_preds)
      results.scores = torch.cat(mlvl_scores)
      results.labels = torch.cat(mlvl_labels)
  
      return self._bbox_post_process(
          results=results,
          cfg=cfg,
          rescale=rescale,
          with_nms=with_nms,
          img_meta=img_meta,
      )
  
imports: import copy
  from typing import Dict, List, Optional, Sequence, Tuple
  import torch
  import torch.nn
  from mmcv.cnn import Scale
  from mmengine import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.dense_heads import CenterNetUpdateHead
  from mmdet.models.utils import unpack_gt_instances
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox2distance
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptInstanceList, reduce_mean
  from .iou_loss import IOULoss
label_desc: Use image node_id 6 for calling the CenterNetRPNHead 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