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: Calculate the loss based on the features extracted by the detection
  head.
  
  Args:
      tl_heats (list[Tensor]): Top-left corner heatmaps for each level
          with shape (N, num_classes, H, W).
      br_heats (list[Tensor]): Bottom-right corner heatmaps for each
          level with shape (N, num_classes, H, W).
      tl_embs (list[Tensor]): Top-left corner embeddings for each level
          with shape (N, corner_emb_channels, H, W).
      br_embs (list[Tensor]): Bottom-right corner embeddings for each
          level with shape (N, corner_emb_channels, H, W).
      tl_offs (list[Tensor]): Top-left corner offsets for each level
          with shape (N, corner_offset_channels, H, W).
      br_offs (list[Tensor]): Bottom-right corner offsets for each level
          with shape (N, corner_offset_channels, H, W).
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance. It usually includes ``bboxes`` and ``labels``
          attributes.
      batch_img_metas (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      batch_gt_instances_ignore (list[:obj:`InstanceData`], optional):
          Specify which bounding boxes can be ignored when computing
          the loss.
  
  Returns:
      dict[str, Tensor]: A dictionary of loss components. Containing the
      following losses:
  
          - det_loss (list[Tensor]): Corner keypoint losses of all
            feature levels.
          - pull_loss (list[Tensor]): Part one of AssociativeEmbedding
            losses of all feature levels.
          - push_loss (list[Tensor]): Part two of AssociativeEmbedding
            losses of all feature levels.
          - off_loss (list[Tensor]): Corner offset losses of all feature
            levels.
docstr_tok: ["Calculate","the","loss","based","on","the","features","extracted","by","the","detection","head",".","Args",":","tl_heats","(","list","[","Tensor","]",")",":","Top-left","corner","heatmaps","for","each","level","with","shape","(","N",",","num_classes",",","H",",","W",")",".","br_heats","(","list","[","Tensor","]",")",":","Bottom-right","corner","heatmaps","for","each","level","with","shape","(","N",",","num_classes",",","H",",","W",")",".","tl_embs","(","list","[","Tensor","]",")",":","Top-left","corner","embeddings","for","each","level","with","shape","(","N",",","corner_emb_channels",",","H",",","W",")",".","br_embs","(","list","[","Tensor","]",")",":","Bottom-right","corner","embeddings","for","each","level","with","shape","(","N",",","corner_emb_channels",",","H",",","W",")",".","tl_offs","(","list","[","Tensor","]",")",":","Top-left","corner","offsets","for","each","level","with","shape","(","N",",","corner_offset_channels",",","H",",","W",")",".","br_offs","(","list","[","Tensor","]",")",":","Bottom-right","corner","offsets","for","each","level","with","shape","(","N",",","corner_offset_channels",",","H",",","W",")",".","batch_gt_instances","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Batch","of","gt_instance",".","It","usually","includes","``","bboxes","``","and","``","labels","``","attributes",".","batch_img_metas","(","list","[","dict","]",")",":","Meta","information","of","each","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","batch_gt_instances_ignore","(","list","[",":","obj",":","`","InstanceData","`","]",",","optional",")",":","Specify","which","bounding","boxes","can","be","ignored","when","computing","the","loss",".","Returns",":","dict","[","str",",","Tensor","]",":","A","dictionary","of","loss","components",".","Containing","the","following","losses",":","-","det_loss","(","list","[","Tensor","]",")",":","Corner","keypoint","losses","of","all","feature","levels",".","-","pull_loss","(","list","[","Tensor","]",")",":","Part","one","of","AssociativeEmbedding","losses","of","all","feature","levels",".","-","push_loss","(","list","[","Tensor","]",")",":","Part","two","of","AssociativeEmbedding","losses","of","all","feature","levels",".","-","off_loss","(","list","[","Tensor","]",")",":","Corner","offset","losses","of","all","feature","levels","."]
code: def loss_by_feat(
      self,
      tl_heats: List[Tensor],
      br_heats: List[Tensor],
      tl_embs: List[Tensor],
      br_embs: List[Tensor],
      tl_offs: List[Tensor],
      br_offs: List[Tensor],
      batch_gt_instances: InstanceList,
      batch_img_metas: List[dict],
      batch_gt_instances_ignore: OptInstanceList = None,
  ) -> dict:
      """Calculate the loss based on the features extracted by the detection
      head.
  
      Args:
          tl_heats (list[Tensor]): Top-left corner heatmaps for each level
              with shape (N, num_classes, H, W).
          br_heats (list[Tensor]): Bottom-right corner heatmaps for each
              level with shape (N, num_classes, H, W).
          tl_embs (list[Tensor]): Top-left corner embeddings for each level
              with shape (N, corner_emb_channels, H, W).
          br_embs (list[Tensor]): Bottom-right corner embeddings for each
              level with shape (N, corner_emb_channels, H, W).
          tl_offs (list[Tensor]): Top-left corner offsets for each level
              with shape (N, corner_offset_channels, H, W).
          br_offs (list[Tensor]): Bottom-right corner offsets for each level
              with shape (N, corner_offset_channels, H, W).
          batch_gt_instances (list[:obj:`InstanceData`]): Batch of
              gt_instance. It usually includes ``bboxes`` and ``labels``
              attributes.
          batch_img_metas (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          batch_gt_instances_ignore (list[:obj:`InstanceData`], optional):
              Specify which bounding boxes can be ignored when computing
              the loss.
  
      Returns:
          dict[str, Tensor]: A dictionary of loss components. Containing the
          following losses:
  
              - det_loss (list[Tensor]): Corner keypoint losses of all
                feature levels.
              - pull_loss (list[Tensor]): Part one of AssociativeEmbedding
                losses of all feature levels.
              - push_loss (list[Tensor]): Part two of AssociativeEmbedding
                losses of all feature levels.
              - off_loss (list[Tensor]): Corner offset losses of all feature
                levels.
      """
      gt_bboxes = [
          gt_instances.bboxes for gt_instances in batch_gt_instances
      ]
      gt_labels = [
          gt_instances.labels for gt_instances in batch_gt_instances
      ]
  
      targets = self.get_targets(
          gt_bboxes,
          gt_labels,
          tl_heats[-1].shape,
          batch_img_metas[0]["batch_input_shape"],
          with_corner_emb=self.with_corner_emb,
      )
      mlvl_targets = [targets for _ in range(self.num_feat_levels)]
      det_losses, pull_losses, push_losses, off_losses = multi_apply(
          self.loss_by_feat_single,
          tl_heats,
          br_heats,
          tl_embs,
          br_embs,
          tl_offs,
          br_offs,
          mlvl_targets,
      )
      loss_dict = dict(det_loss=det_losses, off_loss=off_losses)
      if self.with_corner_emb:
          loss_dict.update(pull_loss=pull_losses, push_loss=push_losses)
      return loss_dict
  
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 10 for calling the CornerHead obj's underlying member method code with example usage: obj.loss_by_feat(tl_heats, br_heats, tl_embs, br_embs, tl_offs, br_offs, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore) and returns: loss_dict