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: Forward function for training mode.
  
  Args:
      x (list[Tensor]): Features from backbone.
      img_metas (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      gt_bboxes (list[Tensor]): Ground truth bboxes of the image,
          shape (num_gts, 4).
      gt_labels (list[Tensor]): Ground truth labels of each box,
          shape (num_gts,).
      gt_keypoints (list[Tensor]): Ground truth keypoints of the image,
          shape (num_gts, K*3).
      gt_areas (list[Tensor]): Ground truth mask areas of each box,
          shape (num_gts,).
      gt_bboxes_ignore (list[Tensor]): Ground truth bboxes to be
          ignored, shape (num_ignored_gts, 4).
      proposal_cfg (mmcv.Config): Test / postprocessing configuration,
          if None, test_cfg would be used.
  
  Returns:
      dict[str, Tensor]: A dictionary of loss components.
docstr_tok: ["Forward","function","for","training","mode",".","Args",":","x","(","list","[","Tensor","]",")",":","Features","from","backbone",".","img_metas","(","list","[","dict","]",")",":","Meta","information","of","each","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","gt_bboxes","(","list","[","Tensor","]",")",":","Ground","truth","bboxes","of","the","image",",","shape","(","num_gts",",","4",")",".","gt_labels","(","list","[","Tensor","]",")",":","Ground","truth","labels","of","each","box",",","shape","(","num_gts",",",")",".","gt_keypoints","(","list","[","Tensor","]",")",":","Ground","truth","keypoints","of","the","image",",","shape","(","num_gts",",","K","*","3",")",".","gt_areas","(","list","[","Tensor","]",")",":","Ground","truth","mask","areas","of","each","box",",","shape","(","num_gts",",",")",".","gt_bboxes_ignore","(","list","[","Tensor","]",")",":","Ground","truth","bboxes","to","be","ignored",",","shape","(","num_ignored_gts",",","4",")",".","proposal_cfg","(","mmcv.Config",")",":","Test","\/","postprocessing","configuration",",","if","None",",","test_cfg","would","be","used",".","Returns",":","dict","[","str",",","Tensor","]",":","A","dictionary","of","loss","components","."]
code: def forward_train(
      self,
      x,
      img_metas,
      gt_bboxes,
      gt_labels=None,
      gt_keypoints=None,
      gt_areas=None,
      gt_bboxes_ignore=None,
      proposal_cfg=None,
      **kwargs,
  ):
      """Forward function for training mode.
  
      Args:
          x (list[Tensor]): Features from backbone.
          img_metas (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          gt_bboxes (list[Tensor]): Ground truth bboxes of the image,
              shape (num_gts, 4).
          gt_labels (list[Tensor]): Ground truth labels of each box,
              shape (num_gts,).
          gt_keypoints (list[Tensor]): Ground truth keypoints of the image,
              shape (num_gts, K*3).
          gt_areas (list[Tensor]): Ground truth mask areas of each box,
              shape (num_gts,).
          gt_bboxes_ignore (list[Tensor]): Ground truth bboxes to be
              ignored, shape (num_ignored_gts, 4).
          proposal_cfg (mmcv.Config): Test / postprocessing configuration,
              if None, test_cfg would be used.
  
      Returns:
          dict[str, Tensor]: A dictionary of loss components.
      """
      assert proposal_cfg is None, '"proposal_cfg" must be None'
      outs = self(x, img_metas)
      memory, mlvl_masks = outs[-2:]
      outs = outs[:-2]
      if gt_labels is None:
          loss_inputs = outs + (
              gt_bboxes,
              gt_keypoints,
              gt_areas,
              img_metas,
          )
      else:
          loss_inputs = outs + (
              gt_bboxes,
              gt_labels,
              gt_keypoints,
              gt_areas,
              img_metas,
          )
      losses_and_targets = self.loss(
          *loss_inputs, gt_bboxes_ignore=gt_bboxes_ignore
      )
      # losses = losses_and_targets
      losses, refine_targets = losses_and_targets
      # get pose refinement loss
      losses = self.forward_refine(
          memory, mlvl_masks, refine_targets, losses, img_metas
      )
      return losses
  
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 6 for calling the PETRHead obj's underlying member method code with example usage: obj.forward_train(x, img_metas, gt_bboxes, gt_labels, gt_keypoints, gt_areas, gt_bboxes_ignore, proposal_cfg) and returns: losses