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: Compute regression and classification targets for one image.
  
  Outputs from a single decoder layer of a single feature level are used.
  
  Args:
      cls_score (Tensor): Box score logits from a single decoder layer
          for one image. Shape [num_query, cls_out_channels].
      kpt_pred (Tensor): Sigmoid outputs from a single decoder layer
          for one image, with normalized coordinate (x_{i}, y_{i}) and
          shape [num_query, K*2].
      gt_labels (Tensor): Ground truth class indices for one image
          with shape (num_gts, ).
      gt_keypoints (Tensor): Ground truth keypoints for one 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 (Tensor): Ground truth mask areas for one image
          with shape (num_gts, ).
      img_meta (dict): Meta information for one image.
  
  Returns:
      tuple[Tensor]: a tuple containing the following for one image.
  
          - labels (Tensor): Labels of each image.
          - label_weights (Tensor): Label weights of each image.
          - kpt_targets (Tensor): Keypoint targets of each image.
          - kpt_weights (Tensor): Keypoint weights of each image.
          - area_targets (Tensor): Area targets of each image.
          - pos_inds (Tensor): Sampled positive indices for each image.
          - neg_inds (Tensor): Sampled negative indices for each image.
docstr_tok: ["Compute","regression","and","classification","targets","for","one","image",".","Outputs","from","a","single","decoder","layer","of","a","single","feature","level","are","used",".","Args",":","cls_score","(","Tensor",")",":","Box","score","logits","from","a","single","decoder","layer","for","one","image",".","Shape","[","num_query",",","cls_out_channels","]",".","kpt_pred","(","Tensor",")",":","Sigmoid","outputs","from","a","single","decoder","layer","for","one","image",",","with","normalized","coordinate","(","x_","{","i","}",",","y_","{","i","}",")","and","shape","[","num_query",",","K","*","2","]",".","gt_labels","(","Tensor",")",":","Ground","truth","class","indices","for","one","image","with","shape","(","num_gts",",",")",".","gt_keypoints","(","Tensor",")",":","Ground","truth","keypoints","for","one","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","(","Tensor",")",":","Ground","truth","mask","areas","for","one","image","with","shape","(","num_gts",",",")",".","img_meta","(","dict",")",":","Meta","information","for","one","image",".","Returns",":","tuple","[","Tensor","]",":","a","tuple","containing","the","following","for","one","image",".","-","labels","(","Tensor",")",":","Labels","of","each","image",".","-","label_weights","(","Tensor",")",":","Label","weights","of","each","image",".","-","kpt_targets","(","Tensor",")",":","Keypoint","targets","of","each","image",".","-","kpt_weights","(","Tensor",")",":","Keypoint","weights","of","each","image",".","-","area_targets","(","Tensor",")",":","Area","targets","of","each","image",".","-","pos_inds","(","Tensor",")",":","Sampled","positive","indices","for","each","image",".","-","neg_inds","(","Tensor",")",":","Sampled","negative","indices","for","each","image","."]
code: def _get_target_single(
      self,
      cls_score,
      kpt_pred,
      gt_labels,
      gt_keypoints,
      gt_areas,
      img_meta,
  ):
      """Compute regression and classification targets for one image.
  
          Outputs from a single decoder layer of a single feature level are used.
  
          Args:
              cls_score (Tensor): Box score logits from a single decoder layer
                  for one image. Shape [num_query, cls_out_channels].
              kpt_pred (Tensor): Sigmoid outputs from a single decoder layer
                  for one image, with normalized coordinate (x_{i}, y_{i}) and
                  shape [num_query, K*2].
              gt_labels (Tensor): Ground truth class indices for one image
                  with shape (num_gts, ).
              gt_keypoints (Tensor): Ground truth keypoints for one 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 (Tensor): Ground truth mask areas for one image
                  with shape (num_gts, ).
              img_meta (dict): Meta information for one image.
  
          Returns:
              tuple[Tensor]: a tuple containing the following for one image.
  
                  - labels (Tensor): Labels of each image.
                  - label_weights (Tensor): Label weights of each image.
                  - kpt_targets (Tensor): Keypoint targets of each image.
                  - kpt_weights (Tensor): Keypoint weights of each image.
                  - area_targets (Tensor): Area targets of each image.
                  - pos_inds (Tensor): Sampled positive indices for each image.
                  - neg_inds (Tensor): Sampled negative indices for each image.
          """
      num_bboxes = kpt_pred.shape[0]
      # assigner and sampler
      assign_result = self.assigner.assign(
          cls_score,
          kpt_pred,
          gt_labels,
          gt_keypoints,
          gt_areas,
          img_meta,
      )
      sampling_result = self.sampler.sample(
          assign_result, kpt_pred, gt_keypoints
      )
  
      pos_inds = sampling_result.pos_inds
      neg_inds = sampling_result.neg_inds
  
      # label targets
      labels = paddle.full(
          (num_bboxes,), self.num_classes, dtype="int64"
      )
      label_weights = paddle.ones((num_bboxes,), dtype=gt_labels.dtype)
      kpt_targets = paddle.zeros_like(kpt_pred)
      kpt_weights = paddle.zeros_like(kpt_pred)
      area_targets = paddle.zeros(
          (kpt_pred.shape[0],), dtype=kpt_pred.dtype
      )
  
      if pos_inds.size == 0:
          return (
              labels,
              label_weights,
              kpt_targets,
              kpt_weights,
              area_targets,
              pos_inds,
              neg_inds,
          )
  
      labels[pos_inds] = gt_labels[
          sampling_result.pos_assigned_gt_inds
      ][..., 0].astype("int64")
  
      img_h, img_w, _ = img_meta["img_shape"]
      # keypoint targets
      pos_gt_kpts = gt_keypoints[sampling_result.pos_assigned_gt_inds]
      pos_gt_kpts = pos_gt_kpts.reshape(
          (len(sampling_result.pos_assigned_gt_inds), -1, 3)
      )
      valid_idx = pos_gt_kpts[:, :, 2] > 0
      pos_kpt_weights = kpt_weights[pos_inds].reshape(
          (pos_gt_kpts.shape[0], kpt_weights.shape[-1] // 2, 2)
      )
      # pos_kpt_weights[valid_idx][...] = 1.0
      pos_kpt_weights = masked_fill(
          pos_kpt_weights, valid_idx.unsqueeze(-1), 1.0
      )
      kpt_weights[pos_inds] = pos_kpt_weights.reshape(
          (pos_kpt_weights.shape[0], kpt_pred.shape[-1])
      )
  
      factor = (
          paddle.to_tensor([img_w, img_h], dtype=kpt_pred.dtype)
          .squeeze()
          .unsqueeze(0)
      )
      pos_gt_kpts_normalized = pos_gt_kpts[..., :2]
      pos_gt_kpts_normalized[..., 0] = (
          pos_gt_kpts_normalized[..., 0] / factor[:, 0:1]
      )
      pos_gt_kpts_normalized[..., 1] = (
          pos_gt_kpts_normalized[..., 1] / factor[:, 1:2]
      )
      kpt_targets[pos_inds] = pos_gt_kpts_normalized.reshape(
          (pos_gt_kpts.shape[0], kpt_pred.shape[-1])
      )
  
      pos_gt_areas = gt_areas[sampling_result.pos_assigned_gt_inds][
          ..., 0
      ]
      area_targets[pos_inds] = pos_gt_areas
  
      return (
          labels,
          label_weights,
          kpt_targets,
          kpt_weights,
          area_targets,
          pos_inds,
          neg_inds,
      )
  
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 11 for calling the PETRHead obj's underlying member method code with example usage: obj._get_target_single(cls_score, kpt_pred, gt_labels, gt_keypoints, gt_areas, img_meta) and returns: labels,  label_weights,  kpt_targets,  kpt_weights,  area_targets,  pos_inds,  neg_inds, labels,  label_weights,  kpt_targets,  kpt_weights,  area_targets,  pos_inds,  neg_inds