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 of the 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_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).
      tl_guiding_shifts (list[Tensor]): Top-left guiding shifts for each
          level with shape (N, guiding_shift_channels, H, W).
      br_guiding_shifts (list[Tensor]): Bottom-right guiding shifts for
          each level with shape (N, guiding_shift_channels, H, W).
      tl_centripetal_shifts (list[Tensor]): Top-left centripetal shifts
          for each level with shape (N, centripetal_shift_channels, H,
          W).
      br_centripetal_shifts (list[Tensor]): Bottom-right centripetal
          shifts for each level with shape (N,
          centripetal_shift_channels, H, W).
      gt_bboxes (list[Tensor]): Ground truth bboxes for each image with
          shape (num_gts, 4) in [left, top, right, bottom] format.
      gt_labels (list[Tensor]): Class indices corresponding to each box.
      img_metas (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      gt_bboxes_ignore (list[Tensor] | None): 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.
          - off_loss (list[Tensor]): Corner offset losses of all feature
            levels.
          - guiding_loss (list[Tensor]): Guiding shift losses of all
            feature levels.
          - centripetal_loss (list[Tensor]): Centripetal shift losses of
            all feature levels.
docstr_tok: ["Compute","losses","of","the","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_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",")",".","tl_guiding_shifts","(","list","[","Tensor","]",")",":","Top-left","guiding","shifts","for","each","level","with","shape","(","N",",","guiding_shift_channels",",","H",",","W",")",".","br_guiding_shifts","(","list","[","Tensor","]",")",":","Bottom-right","guiding","shifts","for","each","level","with","shape","(","N",",","guiding_shift_channels",",","H",",","W",")",".","tl_centripetal_shifts","(","list","[","Tensor","]",")",":","Top-left","centripetal","shifts","for","each","level","with","shape","(","N",",","centripetal_shift_channels",",","H",",","W",")",".","br_centripetal_shifts","(","list","[","Tensor","]",")",":","Bottom-right","centripetal","shifts","for","each","level","with","shape","(","N",",","centripetal_shift_channels",",","H",",","W",")",".","gt_bboxes","(","list","[","Tensor","]",")",":","Ground","truth","bboxes","for","each","image","with","shape","(","num_gts",",","4",")","in","[","left",",","top",",","right",",","bottom","]","format",".","gt_labels","(","list","[","Tensor","]",")",":","Class","indices","corresponding","to","each","box",".","img_metas","(","list","[","dict","]",")",":","Meta","information","of","each","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","gt_bboxes_ignore","(","list","[","Tensor","]","|","None",")",":","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",".","-","off_loss","(","list","[","Tensor","]",")",":","Corner","offset","losses","of","all","feature","levels",".","-","guiding_loss","(","list","[","Tensor","]",")",":","Guiding","shift","losses","of","all","feature","levels",".","-","centripetal_loss","(","list","[","Tensor","]",")",":","Centripetal","shift","losses","of","all","feature","levels","."]
code: def loss(
      self,
      tl_heats,
      br_heats,
      tl_offs,
      br_offs,
      tl_guiding_shifts,
      br_guiding_shifts,
      tl_centripetal_shifts,
      br_centripetal_shifts,
      gt_bboxes,
      gt_labels,
      img_metas,
      gt_bboxes_ignore=None,
  ):
      """Compute losses of the 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_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).
          tl_guiding_shifts (list[Tensor]): Top-left guiding shifts for each
              level with shape (N, guiding_shift_channels, H, W).
          br_guiding_shifts (list[Tensor]): Bottom-right guiding shifts for
              each level with shape (N, guiding_shift_channels, H, W).
          tl_centripetal_shifts (list[Tensor]): Top-left centripetal shifts
              for each level with shape (N, centripetal_shift_channels, H,
              W).
          br_centripetal_shifts (list[Tensor]): Bottom-right centripetal
              shifts for each level with shape (N,
              centripetal_shift_channels, H, W).
          gt_bboxes (list[Tensor]): Ground truth bboxes for each image with
              shape (num_gts, 4) in [left, top, right, bottom] format.
          gt_labels (list[Tensor]): Class indices corresponding to each box.
          img_metas (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          gt_bboxes_ignore (list[Tensor] | None): 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.
              - off_loss (list[Tensor]): Corner offset losses of all feature
                levels.
              - guiding_loss (list[Tensor]): Guiding shift losses of all
                feature levels.
              - centripetal_loss (list[Tensor]): Centripetal shift losses of
                all feature levels.
      """
      targets = self.get_targets(
          gt_bboxes,
          gt_labels,
          tl_heats[-1].shape,
          img_metas[0]["pad_shape"],
          with_corner_emb=self.with_corner_emb,
          with_guiding_shift=True,
          with_centripetal_shift=True,
      )
      mlvl_targets = [targets for _ in range(self.num_feat_levels)]
      [
          det_losses,
          off_losses,
          guiding_losses,
          centripetal_losses,
      ] = multi_apply(
          self.loss_single,
          tl_heats,
          br_heats,
          tl_offs,
          br_offs,
          tl_guiding_shifts,
          br_guiding_shifts,
          tl_centripetal_shifts,
          br_centripetal_shifts,
          mlvl_targets,
      )
      loss_dict = dict(
          det_loss=det_losses,
          off_loss=off_losses,
          guiding_loss=guiding_losses,
          centripetal_loss=centripetal_losses,
      )
      return loss_dict
  
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 6 for calling the CentripetalHead obj's underlying member method code with example usage: obj.loss(tl_heats, br_heats, tl_offs, br_offs, tl_guiding_shifts, br_guiding_shifts, tl_centripetal_shifts, br_centripetal_shifts, gt_bboxes, gt_labels, img_metas, gt_bboxes_ignore) and returns: loss_dict