class_docstr: Head of `End-to-End Multi-Person Pose Estimation with Transformers`.
  
  Args:
      num_classes (int): Number of categories excluding the background.
      in_channels (int): Number of channels in the input feature map.
      num_query (int): Number of query in Transformer.
      num_kpt_fcs (int, optional): Number of fully-connected layers used in
          `FFN`, which is then used for the keypoint regression head.
          Default 2.
      transformer (obj:`mmcv.ConfigDict`|dict): ConfigDict is used for
          building the Encoder and Decoder. Default: None.
      sync_cls_avg_factor (bool): Whether to sync the avg_factor of
          all ranks. Default to False.
      positional_encoding (obj:`mmcv.ConfigDict`|dict):
          Config for position encoding.
      loss_cls (obj:`mmcv.ConfigDict`|dict): Config of the
          classification loss. Default `CrossEntropyLoss`.
      loss_kpt (obj:`mmcv.ConfigDict`|dict): Config of the
          regression loss. Default `L1Loss`.
      loss_oks (obj:`mmcv.ConfigDict`|dict): Config of the
          regression oks loss. Default `OKSLoss`.
      loss_hm (obj:`mmcv.ConfigDict`|dict): Config of the
          regression heatmap loss. Default `NegLoss`.
      as_two_stage (bool) : Whether to generate the proposal from
          the outputs of encoder.
      with_kpt_refine (bool): Whether to refine the reference points
          in the decoder. Defaults to True.
      test_cfg (obj:`mmcv.ConfigDict`|dict): Testing config of
          transformer head.
      init_cfg (dict or list[dict], optional): Initialization config dict.
          Default: None.
class_docstr_tok: ["Head","of","`","End-to-End","Multi-Person","Pose","Estimation","with","Transformers","`",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","num_query","(","int",")",":","Number","of","query","in","Transformer",".","num_kpt_fcs","(","int",",","optional",")",":","Number","of","fully-connected","layers","used","in","`","FFN","`",",","which","is","then","used","for","the","keypoint","regression","head",".","Default","2.","transformer","(","obj",":","`","mmcv.ConfigDict","`","|dict",")",":","ConfigDict","is","used","for","building","the","Encoder","and","Decoder",".","Default",":","None",".","sync_cls_avg_factor","(","bool",")",":","Whether","to","sync","the","avg_factor","of","all","ranks",".","Default","to","False",".","positional_encoding","(","obj",":","`","mmcv.ConfigDict","`","|dict",")",":","Config","for","position","encoding",".","loss_cls","(","obj",":","`","mmcv.ConfigDict","`","|dict",")",":","Config","of","the","classification","loss",".","Default","`","CrossEntropyLoss","`",".","loss_kpt","(","obj",":","`","mmcv.ConfigDict","`","|dict",")",":","Config","of","the","regression","loss",".","Default","`","L1Loss","`",".","loss_oks","(","obj",":","`","mmcv.ConfigDict","`","|dict",")",":","Config","of","the","regression","oks","loss",".","Default","`","OKSLoss","`",".","loss_hm","(","obj",":","`","mmcv.ConfigDict","`","|dict",")",":","Config","of","the","regression","heatmap","loss",".","Default","`","NegLoss","`",".","as_two_stage","(","bool",")",":","Whether","to","generate","the","proposal","from","the","outputs","of","encoder",".","with_kpt_refine","(","bool",")",":","Whether","to","refine","the","reference","points","in","the","decoder",".","Defaults","to","True",".","test_cfg","(","obj",":","`","mmcv.ConfigDict","`","|dict",")",":","Testing","config","of","transformer","head",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict",".","Default",":","None","."]
docstr: Loss function for outputs from a single decoder layer of a single
  feature level.
  
  Args:
      cls_scores (Tensor): Box score logits from a single decoder layer
          for all images. Shape [bs, num_query, cls_out_channels].
      kpt_preds (Tensor): Sigmoid outputs from a single decoder layer
          for all images, with normalized coordinate (x_{i}, y_{i}) and
          shape [bs, num_query, K*2].
      gt_labels_list (list[Tensor]): Ground truth class indices for each
          image with shape (num_gts, ).
      gt_keypoints_list (list[Tensor]): Ground truth keypoints for each
          image with shape (num_gts, K*3) in [p^{1}_x, p^{1}_y, p^{1}_v,
          ..., p^{K}_x, p^{K}_y, p^{K}_v] format.
      gt_areas_list (list[Tensor]): Ground truth mask areas for each
          image with shape (num_gts, ).
      img_metas (list[dict]): List of image meta information.
  
  Returns:
      dict[str, Tensor]: A dictionary of loss components for outputs from
          a single decoder layer.
docstr_tok: ["Loss","function","for","outputs","from","a","single","decoder","layer","of","a","single","feature","level",".","Args",":","cls_scores","(","Tensor",")",":","Box","score","logits","from","a","single","decoder","layer","for","all","images",".","Shape","[","bs",",","num_query",",","cls_out_channels","]",".","kpt_preds","(","Tensor",")",":","Sigmoid","outputs","from","a","single","decoder","layer","for","all","images",",","with","normalized","coordinate","(","x_","{","i","}",",","y_","{","i","}",")","and","shape","[","bs",",","num_query",",","K","*","2","]",".","gt_labels_list","(","list","[","Tensor","]",")",":","Ground","truth","class","indices","for","each","image","with","shape","(","num_gts",",",")",".","gt_keypoints_list","(","list","[","Tensor","]",")",":","Ground","truth","keypoints","for","each","image","with","shape","(","num_gts",",","K","*","3",")","in","[","p^","{","1","}","_x",",","p^","{","1","}","_y",",","p^","{","1","}","_v",",","...",",","p^","{","K","}","_x",",","p^","{","K","}","_y",",","p^","{","K","}","_v","]","format",".","gt_areas_list","(","list","[","Tensor","]",")",":","Ground","truth","mask","areas","for","each","image","with","shape","(","num_gts",",",")",".","img_metas","(","list","[","dict","]",")",":","List","of","image","meta","information",".","Returns",":","dict","[","str",",","Tensor","]",":","A","dictionary","of","loss","components","for","outputs","from","a","single","decoder","layer","."]
code: def loss_single_rpn(
      self,
      cls_scores,
      kpt_preds,
      gt_labels_list,
      gt_keypoints_list,
      gt_areas_list,
      img_metas,
  ):
      """Loss function for outputs from a single decoder layer of a single
      feature level.
  
      Args:
          cls_scores (Tensor): Box score logits from a single decoder layer
              for all images. Shape [bs, num_query, cls_out_channels].
          kpt_preds (Tensor): Sigmoid outputs from a single decoder layer
              for all images, with normalized coordinate (x_{i}, y_{i}) and
              shape [bs, num_query, K*2].
          gt_labels_list (list[Tensor]): Ground truth class indices for each
              image with shape (num_gts, ).
          gt_keypoints_list (list[Tensor]): Ground truth keypoints for each
              image with shape (num_gts, K*3) in [p^{1}_x, p^{1}_y, p^{1}_v,
              ..., p^{K}_x, p^{K}_y, p^{K}_v] format.
          gt_areas_list (list[Tensor]): Ground truth mask areas for each
              image with shape (num_gts, ).
          img_metas (list[dict]): List of image meta information.
  
      Returns:
          dict[str, Tensor]: A dictionary of loss components for outputs from
              a single decoder layer.
      """
      num_imgs = cls_scores.shape[0]
      cls_scores_list = [cls_scores[i] for i in range(num_imgs)]
      kpt_preds_list = [kpt_preds[i] for i in range(num_imgs)]
      cls_reg_targets = self.get_targets(
          cls_scores_list,
          kpt_preds_list,
          gt_labels_list,
          gt_keypoints_list,
          gt_areas_list,
          img_metas,
      )
      (
          labels_list,
          label_weights_list,
          kpt_targets_list,
          kpt_weights_list,
          area_targets_list,
          num_total_pos,
          num_total_neg,
      ) = cls_reg_targets
      labels = paddle.concat(labels_list, 0)
      label_weights = paddle.concat(label_weights_list, 0)
      kpt_targets = paddle.concat(kpt_targets_list, 0)
      kpt_weights = paddle.concat(kpt_weights_list, 0)
  
      # classification loss
      cls_scores = cls_scores.reshape((-1, self.cls_out_channels))
      # construct weighted avg_factor to match with the official DETR repo
      cls_avg_factor = (
          num_total_pos * 1.0 + num_total_neg * self.bg_cls_weight
      )
      if self.sync_cls_avg_factor:
          cls_avg_factor = reduce_mean(
              paddle.to_tensor([cls_avg_factor], dtype=cls_scores.dtype)
          )
      cls_avg_factor = max(cls_avg_factor, 1)
  
      cls_avg_factor = max(cls_avg_factor, 1)
      loss_cls = self.loss_cls(
          cls_scores, labels, label_weights, avg_factor=cls_avg_factor
      )
  
      # Compute the average number of gt keypoints accross all gpus, for
      # normalization purposes
      # num_total_pos = loss_cls.to_tensor([num_total_pos])
      # num_total_pos = paddle.clip(reduce_mean(num_total_pos), min=1).item()
  
      # keypoint regression loss
      kpt_preds = kpt_preds.reshape((-1, kpt_preds.shape[-1]))
      num_valid_kpt = paddle.clip(
          reduce_mean(kpt_weights.sum()), min=1
      ).item()
      # assert num_valid_kpt == (kpt_targets>0).sum().item()
      loss_kpt = self.loss_kpt_rpn(
          kpt_preds, kpt_targets, kpt_weights, avg_factor=num_valid_kpt
      )
  
      return loss_cls, loss_kpt
  
imports: import copy
  import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from ppdet.core.workspace import register
  import paddle.distributed
  from ..transformers.petr_transformer import inverse_sigmoid, masked_fill
  from ..initializer import constant_, normal_
  from functools import partial
label_desc: Use image node_id 12 for calling the PETRHead obj's underlying member method code with example usage: obj.loss_single_rpn(cls_scores, kpt_preds, gt_labels_list, gt_keypoints_list, gt_areas_list, img_metas) and returns: loss_cls,  loss_kpt