class_docstr: Head of CornerNet: Detecting Objects as Paired Keypoints.
  
  Code is modified from the `official github repo
  <https://github.com/princeton-vl/CornerNet/blob/master/models/py_utils/
  kp.py#L73>`_ .
  
  More details can be found in the `paper
  <https://arxiv.org/abs/1808.01244>`_ .
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      num_feat_levels (int): Levels of feature from the previous module.
          2 for HourglassNet-104 and 1 for HourglassNet-52. Because
          HourglassNet-104 outputs the final feature and intermediate
          supervision feature and HourglassNet-52 only outputs the final
          feature. Defaults to 2.
      corner_emb_channels (int): Channel of embedding vector. Defaults to 1.
      train_cfg (:obj:`ConfigDict` or dict, optional): Training config.
          Useless in CornerHead, but we keep this variable for
          SingleStageDetector.
      test_cfg (:obj:`ConfigDict` or dict, optional): Testing config of
          CornerHead.
      loss_heatmap (:obj:`ConfigDict` or dict): Config of corner heatmap
          loss. Defaults to GaussianFocalLoss.
      loss_embedding (:obj:`ConfigDict` or dict): Config of corner embedding
          loss. Defaults to AssociativeEmbeddingLoss.
      loss_offset (:obj:`ConfigDict` or dict): Config of corner offset loss.
          Defaults to SmoothL1Loss.
      init_cfg (:obj:`ConfigDict` or dict, optional): the config to control
          the initialization.
class_docstr_tok: ["Head","of","CornerNet",":","Detecting","Objects","as","Paired","Keypoints",".","Code","is","modified","from","the","`","official","github","repo","<","https",":","\/\/github.com\/princeton-vl\/CornerNet\/blob\/master\/models\/py_utils\/","kp.py","#","L73",">","`","_",".","More","details","can","be","found","in","the","`","paper","<","https",":","\/\/arxiv.org\/abs\/1808.01244",">","`","_",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","num_feat_levels","(","int",")",":","Levels","of","feature","from","the","previous","module",".","2","for","HourglassNet-104","and","1","for","HourglassNet-52",".","Because","HourglassNet-104","outputs","the","final","feature","and","intermediate","supervision","feature","and","HourglassNet-52","only","outputs","the","final","feature",".","Defaults","to","2.","corner_emb_channels","(","int",")",":","Channel","of","embedding","vector",".","Defaults","to","1.","train_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Training","config",".","Useless","in","CornerHead",",","but","we","keep","this","variable","for","SingleStageDetector",".","test_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Testing","config","of","CornerHead",".","loss_heatmap","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","corner","heatmap","loss",".","Defaults","to","GaussianFocalLoss",".","loss_embedding","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","corner","embedding","loss",".","Defaults","to","AssociativeEmbeddingLoss",".","loss_offset","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","corner","offset","loss",".","Defaults","to","SmoothL1Loss",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","the","config","to","control","the","initialization","."]
docstr: Transform a single image's features extracted from the head into
  bbox results.
  
  Args:
      tl_heat (Tensor): Top-left corner heatmap for current level with
          shape (N, num_classes, H, W).
      br_heat (Tensor): Bottom-right corner heatmap for current level
          with shape (N, num_classes, H, W).
      tl_off (Tensor): Top-left corner offset for current level with
          shape (N, corner_offset_channels, H, W).
      br_off (Tensor): Bottom-right corner offset for current level with
          shape (N, corner_offset_channels, H, W).
      img_meta (dict): Meta information of current image, e.g.,
          image size, scaling factor, etc.
      tl_emb (Tensor): Top-left corner embedding for current level with
          shape (N, corner_emb_channels, H, W).
      br_emb (Tensor): Bottom-right corner embedding for current level
          with shape (N, corner_emb_channels, H, W).
      tl_centripetal_shift: Top-left corner's centripetal shift for
          current level with shape (N, 2, H, W).
      br_centripetal_shift: Bottom-right corner's centripetal shift for
          current level with shape (N, 2, H, W).
      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",":","tl_heat","(","Tensor",")",":","Top-left","corner","heatmap","for","current","level","with","shape","(","N",",","num_classes",",","H",",","W",")",".","br_heat","(","Tensor",")",":","Bottom-right","corner","heatmap","for","current","level","with","shape","(","N",",","num_classes",",","H",",","W",")",".","tl_off","(","Tensor",")",":","Top-left","corner","offset","for","current","level","with","shape","(","N",",","corner_offset_channels",",","H",",","W",")",".","br_off","(","Tensor",")",":","Bottom-right","corner","offset","for","current","level","with","shape","(","N",",","corner_offset_channels",",","H",",","W",")",".","img_meta","(","dict",")",":","Meta","information","of","current","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","tl_emb","(","Tensor",")",":","Top-left","corner","embedding","for","current","level","with","shape","(","N",",","corner_emb_channels",",","H",",","W",")",".","br_emb","(","Tensor",")",":","Bottom-right","corner","embedding","for","current","level","with","shape","(","N",",","corner_emb_channels",",","H",",","W",")",".","tl_centripetal_shift",":","Top-left","corner","'s","centripetal","shift","for","current","level","with","shape","(","N",",","2",",","H",",","W",")",".","br_centripetal_shift",":","Bottom-right","corner","'s","centripetal","shift","for","current","level","with","shape","(","N",",","2",",","H",",","W",")",".","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,
      tl_heat: Tensor,
      br_heat: Tensor,
      tl_off: Tensor,
      br_off: Tensor,
      img_meta: dict,
      tl_emb: Optional[Tensor] = None,
      br_emb: Optional[Tensor] = None,
      tl_centripetal_shift: Optional[Tensor] = None,
      br_centripetal_shift: Optional[Tensor] = None,
      rescale: bool = False,
      with_nms: bool = True,
  ) -> InstanceData:
      """Transform a single image's features extracted from the head into
      bbox results.
  
      Args:
          tl_heat (Tensor): Top-left corner heatmap for current level with
              shape (N, num_classes, H, W).
          br_heat (Tensor): Bottom-right corner heatmap for current level
              with shape (N, num_classes, H, W).
          tl_off (Tensor): Top-left corner offset for current level with
              shape (N, corner_offset_channels, H, W).
          br_off (Tensor): Bottom-right corner offset for current level with
              shape (N, corner_offset_channels, H, W).
          img_meta (dict): Meta information of current image, e.g.,
              image size, scaling factor, etc.
          tl_emb (Tensor): Top-left corner embedding for current level with
              shape (N, corner_emb_channels, H, W).
          br_emb (Tensor): Bottom-right corner embedding for current level
              with shape (N, corner_emb_channels, H, W).
          tl_centripetal_shift: Top-left corner's centripetal shift for
              current level with shape (N, 2, H, W).
          br_centripetal_shift: Bottom-right corner's centripetal shift for
              current level with shape (N, 2, H, W).
          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).
      """
      if isinstance(img_meta, (list, tuple)):
          img_meta = img_meta[0]
  
      batch_bboxes, batch_scores, batch_clses = self._decode_heatmap(
          tl_heat=tl_heat.sigmoid(),
          br_heat=br_heat.sigmoid(),
          tl_off=tl_off,
          br_off=br_off,
          tl_emb=tl_emb,
          br_emb=br_emb,
          tl_centripetal_shift=tl_centripetal_shift,
          br_centripetal_shift=br_centripetal_shift,
          img_meta=img_meta,
          k=self.test_cfg.corner_topk,
          kernel=self.test_cfg.local_maximum_kernel,
          distance_threshold=self.test_cfg.distance_threshold,
      )
  
      if rescale and "scale_factor" in img_meta:
          batch_bboxes /= batch_bboxes.new_tensor(
              img_meta["scale_factor"]
          ).repeat((1, 2))
  
      bboxes = batch_bboxes.view([-1, 4])
      scores = batch_scores.view(-1)
      clses = batch_clses.view(-1)
  
      det_bboxes = torch.cat([bboxes, scores.unsqueeze(-1)], -1)
      keepinds = det_bboxes[:, -1] > -0.1
      det_bboxes = det_bboxes[keepinds]
      det_labels = clses[keepinds]
  
      if with_nms:
          det_bboxes, det_labels = self._bboxes_nms(
              det_bboxes, det_labels, self.test_cfg
          )
  
      results = InstanceData()
      results.bboxes = det_bboxes[..., :4]
      results.scores = det_bboxes[..., 4]
      results.labels = det_labels
      return results
  
imports: from logging import warning
  from math import ceil, log
  from typing import List, Optional, Sequence, Tuple
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule
  from mmcv.ops import CornerPool, batched_nms
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModule, bias_init_with_prob
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptInstanceList, OptMultiConfig
  from ..utils import gather_feat, gaussian_radius, gen_gaussian_target, get_local_maximum, get_topk_from_heatmap, multi_apply, transpose_and_gather_feat
  from .base_dense_head import BaseDenseHead
label_desc: Use image node_id 13 for calling the CornerHead obj's underlying member method code with example usage: obj._predict_by_feat_single(tl_heat, br_heat, tl_off, br_off, img_meta, tl_emb, br_emb, tl_centripetal_shift, br_centripetal_shift, rescale, with_nms) and returns: results