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. Default: 2.
      corner_emb_channels (int): Channel of embedding vector. Default: 1.
      train_cfg (dict | None): Training config. Useless in CornerHead,
          but we keep this variable for SingleStageDetector. Default: None.
      test_cfg (dict | None): Testing config of CornerHead. Default: None.
      loss_heatmap (dict | None): Config of corner heatmap loss. Default:
          GaussianFocalLoss.
      loss_embedding (dict | None): Config of corner embedding loss. Default:
          AssociativeEmbeddingLoss.
      loss_offset (dict | None): Config of corner offset loss. Default:
          SmoothL1Loss.
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",".","Default",":","2.","corner_emb_channels","(","int",")",":","Channel","of","embedding","vector",".","Default",":","1.","train_cfg","(","dict","|","None",")",":","Training","config",".","Useless","in","CornerHead",",","but","we","keep","this","variable","for","SingleStageDetector",".","Default",":","None",".","test_cfg","(","dict","|","None",")",":","Testing","config","of","CornerHead",".","Default",":","None",".","loss_heatmap","(","dict","|","None",")",":","Config","of","corner","heatmap","loss",".","Default",":","GaussianFocalLoss",".","loss_embedding","(","dict","|","None",")",":","Config","of","corner","embedding","loss",".","Default",":","AssociativeEmbeddingLoss",".","loss_offset","(","dict","|","None",")",":","Config","of","corner","offset","loss",".","Default",":","SmoothL1Loss","."]
docstr: Get top k positions from heatmap.
  
  Args:
      scores (Tensor): Target heatmap with shape
          [batch, num_classes, height, width].
      k (int): Target number. Default: 20.
  
  Returns:
      tuple[torch.Tensor]: Scores, indexes, categories and coords of
          topk keypoint. Containing following Tensors:
  
      - topk_scores (Tensor): Max scores of each topk keypoint.
      - topk_inds (Tensor): Indexes of each topk keypoint.
      - topk_clses (Tensor): Categories of each topk keypoint.
      - topk_ys (Tensor): Y-coord of each topk keypoint.
      - topk_xs (Tensor): X-coord of each topk keypoint.
docstr_tok: ["Get","top","k","positions","from","heatmap",".","Args",":","scores","(","Tensor",")",":","Target","heatmap","with","shape","[","batch",",","num_classes",",","height",",","width","]",".","k","(","int",")",":","Target","number",".","Default",":","20",".","Returns",":","tuple","[","torch.Tensor","]",":","Scores",",","indexes",",","categories","and","coords","of","topk","keypoint",".","Containing","following","Tensors",":","-","topk_scores","(","Tensor",")",":","Max","scores","of","each","topk","keypoint",".","-","topk_inds","(","Tensor",")",":","Indexes","of","each","topk","keypoint",".","-","topk_clses","(","Tensor",")",":","Categories","of","each","topk","keypoint",".","-","topk_ys","(","Tensor",")",":","Y-coord","of","each","topk","keypoint",".","-","topk_xs","(","Tensor",")",":","X-coord","of","each","topk","keypoint","."]
code: def _topk(self, scores, k=20):
      """Get top k positions from heatmap.
  
      Args:
          scores (Tensor): Target heatmap with shape
              [batch, num_classes, height, width].
          k (int): Target number. Default: 20.
  
      Returns:
          tuple[torch.Tensor]: Scores, indexes, categories and coords of
              topk keypoint. Containing following Tensors:
  
          - topk_scores (Tensor): Max scores of each topk keypoint.
          - topk_inds (Tensor): Indexes of each topk keypoint.
          - topk_clses (Tensor): Categories of each topk keypoint.
          - topk_ys (Tensor): Y-coord of each topk keypoint.
          - topk_xs (Tensor): X-coord of each topk keypoint.
      """
      batch, _, height, width = scores.size()
      topk_scores, topk_inds = torch.topk(scores.view(batch, -1), k)
      topk_clses = topk_inds // (height * width)
      topk_inds = topk_inds % (height * width)
      topk_ys = topk_inds // width
      topk_xs = (topk_inds % width).int().float()
      return topk_scores, topk_inds, topk_clses, topk_ys, topk_xs
  
imports: from math import ceil, log
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, bias_init_with_prob
  from mmcv.ops import CornerPool, batched_nms
  from mmdet.core import multi_apply
  from ..builder import HEADS, build_loss
  from ..utils import gaussian_radius, gen_gaussian_target
  from .base_dense_head import BaseDenseHead
label_desc: Use image node_id 18 for calling the CornerHead obj's underlying member method code with example usage: obj._topk(scores, k) and returns: topk_scores,  topk_inds,  topk_clses,  topk_ys,  topk_xs