class_docstr: Head of CentripetalNet: Pursuing High-quality Keypoint Pairs for Object
  Detection.
  
  CentripetalHead inherits from :class:`CornerHead`. It removes the
  embedding branch and adds guiding shift and centripetal shift branches.
  More details can be found in the `paper
  <https://arxiv.org/abs/2003.09119>`_ .
  
  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. 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.
      loss_guiding_shift (dict): Config of guiding shift loss. Default:
          SmoothL1Loss.
      loss_centripetal_shift (dict): Config of centripetal shift loss.
          Default: SmoothL1Loss.
docstr: Compute losses for single level.
  
  Args:
      tl_hmp (Tensor): Top-left corner heatmap for current level with
          shape (N, num_classes, H, W).
      br_hmp (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).
      tl_guiding_shift (Tensor): Top-left guiding shift for current level
          with shape (N, guiding_shift_channels, H, W).
      br_guiding_shift (Tensor): Bottom-right guiding shift for current
          level with shape (N, guiding_shift_channels, H, W).
      tl_centripetal_shift (Tensor): Top-left centripetal shift for
          current level with shape (N, centripetal_shift_channels, H, W).
      br_centripetal_shift (Tensor): Bottom-right centripetal shift for
          current level with shape (N, centripetal_shift_channels, H, W).
      targets (dict): Corner target generated by `get_targets`.
  
  Returns:
      tuple[torch.Tensor]: Losses of the head's differnet branches
      containing the following losses:
  
          - det_loss (Tensor): Corner keypoint loss.
          - off_loss (Tensor): Corner offset loss.
          - guiding_loss (Tensor): Guiding shift loss.
          - centripetal_loss (Tensor): Centripetal shift loss.
docstr_tok: ["Compute","losses","for","single","level",".","Args",":","tl_hmp","(","Tensor",")",":","Top-left","corner","heatmap","for","current","level","with","shape","(","N",",","num_classes",",","H",",","W",")",".","br_hmp","(","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",")",".","tl_guiding_shift","(","Tensor",")",":","Top-left","guiding","shift","for","current","level","with","shape","(","N",",","guiding_shift_channels",",","H",",","W",")",".","br_guiding_shift","(","Tensor",")",":","Bottom-right","guiding","shift","for","current","level","with","shape","(","N",",","guiding_shift_channels",",","H",",","W",")",".","tl_centripetal_shift","(","Tensor",")",":","Top-left","centripetal","shift","for","current","level","with","shape","(","N",",","centripetal_shift_channels",",","H",",","W",")",".","br_centripetal_shift","(","Tensor",")",":","Bottom-right","centripetal","shift","for","current","level","with","shape","(","N",",","centripetal_shift_channels",",","H",",","W",")",".","targets","(","dict",")",":","Corner","target","generated","by","`","get_targets","`",".","Returns",":","tuple","[","torch.Tensor","]",":","Losses","of","the","head","'s","differnet","branches","containing","the","following","losses",":","-","det_loss","(","Tensor",")",":","Corner","keypoint","loss",".","-","off_loss","(","Tensor",")",":","Corner","offset","loss",".","-","guiding_loss","(","Tensor",")",":","Guiding","shift","loss",".","-","centripetal_loss","(","Tensor",")",":","Centripetal","shift","loss","."]
code: def loss_single(
      self,
      tl_hmp,
      br_hmp,
      tl_off,
      br_off,
      tl_guiding_shift,
      br_guiding_shift,
      tl_centripetal_shift,
      br_centripetal_shift,
      targets,
  ):
      """Compute losses for single level.
  
      Args:
          tl_hmp (Tensor): Top-left corner heatmap for current level with
              shape (N, num_classes, H, W).
          br_hmp (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).
          tl_guiding_shift (Tensor): Top-left guiding shift for current level
              with shape (N, guiding_shift_channels, H, W).
          br_guiding_shift (Tensor): Bottom-right guiding shift for current
              level with shape (N, guiding_shift_channels, H, W).
          tl_centripetal_shift (Tensor): Top-left centripetal shift for
              current level with shape (N, centripetal_shift_channels, H, W).
          br_centripetal_shift (Tensor): Bottom-right centripetal shift for
              current level with shape (N, centripetal_shift_channels, H, W).
          targets (dict): Corner target generated by `get_targets`.
  
      Returns:
          tuple[torch.Tensor]: Losses of the head's differnet branches
          containing the following losses:
  
              - det_loss (Tensor): Corner keypoint loss.
              - off_loss (Tensor): Corner offset loss.
              - guiding_loss (Tensor): Guiding shift loss.
              - centripetal_loss (Tensor): Centripetal shift loss.
      """
      targets["corner_embedding"] = None
  
      det_loss, _, _, off_loss = super().loss_single(
          tl_hmp, br_hmp, None, None, tl_off, br_off, targets
      )
  
      gt_tl_guiding_shift = targets["topleft_guiding_shift"]
      gt_br_guiding_shift = targets["bottomright_guiding_shift"]
      gt_tl_centripetal_shift = targets["topleft_centripetal_shift"]
      gt_br_centripetal_shift = targets["bottomright_centripetal_shift"]
  
      gt_tl_heatmap = targets["topleft_heatmap"]
      gt_br_heatmap = targets["bottomright_heatmap"]
      # We only compute the offset loss at the real corner position.
      # The value of real corner would be 1 in heatmap ground truth.
      # The mask is computed in class agnostic mode and its shape is
      # batch * 1 * width * height.
      tl_mask = (
          gt_tl_heatmap.eq(1)
          .sum(1)
          .gt(0)
          .unsqueeze(1)
          .type_as(gt_tl_heatmap)
      )
      br_mask = (
          gt_br_heatmap.eq(1)
          .sum(1)
          .gt(0)
          .unsqueeze(1)
          .type_as(gt_br_heatmap)
      )
  
      # Guiding shift loss
      tl_guiding_loss = self.loss_guiding_shift(
          tl_guiding_shift,
          gt_tl_guiding_shift,
          tl_mask,
          avg_factor=tl_mask.sum(),
      )
      br_guiding_loss = self.loss_guiding_shift(
          br_guiding_shift,
          gt_br_guiding_shift,
          br_mask,
          avg_factor=br_mask.sum(),
      )
      guiding_loss = (tl_guiding_loss + br_guiding_loss) / 2.0
      # Centripetal shift loss
      tl_centripetal_loss = self.loss_centripetal_shift(
          tl_centripetal_shift,
          gt_tl_centripetal_shift,
          tl_mask,
          avg_factor=tl_mask.sum(),
      )
      br_centripetal_loss = self.loss_centripetal_shift(
          br_centripetal_shift,
          gt_br_centripetal_shift,
          br_mask,
          avg_factor=br_mask.sum(),
      )
      centripetal_loss = (
          tl_centripetal_loss + br_centripetal_loss
      ) / 2.0
  
      return det_loss, off_loss, guiding_loss, centripetal_loss
  
file_path: insightface/detection/scrfd/mmdet/models/dense_heads/centripetal_head.py
imports: import torch.nn
  from mmcv.cnn import ConvModule, normal_init
  from mmcv.ops import DeformConv2d
  from mmdet.core import multi_apply
  from ..builder import HEADS, build_loss
  from .corner_head import CornerHead
label_desc: Use image node_id 7 for calling the CentripetalHead obj's underlying member method code with example usage: obj.loss_single(tl_hmp, br_hmp, tl_off, br_off, tl_guiding_shift, br_guiding_shift, tl_centripetal_shift, br_centripetal_shift, targets) and returns: det_loss,  off_loss,  guiding_loss,  centripetal_loss