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: Transform outputs from the last decoder layer into bbox predictions
  for each image.
  
  Args:
      cls_score (Tensor): Box score logits from the last decoder layer
          for each image. Shape [num_query, cls_out_channels].
      kpt_pred (Tensor): Sigmoid outputs from the last decoder layer
          for each image, with coordinate format (x_{i}, y_{i}) and
          shape [num_query, K*2].
      img_shape (tuple[int]): Shape of input image, (height, width, 3).
      scale_factor (ndarray, optional): Scale factor of the image arange
          as (w_scale, h_scale, w_scale, h_scale).
      rescale (bool, optional): If True, return boxes in original image
          space. Default False.
  
  Returns:
      tuple[Tensor]: Results of detected bboxes and labels.
  
          - det_bboxes: Predicted bboxes with shape [num_query, 5],
              where the first 4 columns are bounding box positions
              (tl_x, tl_y, br_x, br_y) and the 5-th column are scores
              between 0 and 1.
          - det_labels: Predicted labels of the corresponding box with
              shape [num_query].
          - det_kpts: Predicted keypoints with shape [num_query, K, 3].
docstr_tok: ["Transform","outputs","from","the","last","decoder","layer","into","bbox","predictions","for","each","image",".","Args",":","cls_score","(","Tensor",")",":","Box","score","logits","from","the","last","decoder","layer","for","each","image",".","Shape","[","num_query",",","cls_out_channels","]",".","kpt_pred","(","Tensor",")",":","Sigmoid","outputs","from","the","last","decoder","layer","for","each","image",",","with","coordinate","format","(","x_","{","i","}",",","y_","{","i","}",")","and","shape","[","num_query",",","K","*","2","]",".","img_shape","(","tuple","[","int","]",")",":","Shape","of","input","image",",","(","height",",","width",",","3",")",".","scale_factor","(","ndarray",",","optional",")",":","Scale","factor","of","the","image","arange","as","(","w_scale",",","h_scale",",","w_scale",",","h_scale",")",".","rescale","(","bool",",","optional",")",":","If","True",",","return","boxes","in","original","image","space",".","Default","False",".","Returns",":","tuple","[","Tensor","]",":","Results","of","detected","bboxes","and","labels",".","-","det_bboxes",":","Predicted","bboxes","with","shape","[","num_query",",","5","]",",","where","the","first","4","columns","are","bounding","box","positions","(","tl_x",",","tl_y",",","br_x",",","br_y",")","and","the","5-th","column","are","scores","between","0","and","1",".","-","det_labels",":","Predicted","labels","of","the","corresponding","box","with","shape","[","num_query","]",".","-","det_kpts",":","Predicted","keypoints","with","shape","[","num_query",",","K",",","3","]","."]
code: def _get_bboxes_single(
      self,
      cls_score,
      kpt_pred,
      img_shape,
      scale_factor,
      memory,
      mlvl_masks,
      rescale=False,
  ):
      """Transform outputs from the last decoder layer into bbox predictions
      for each image.
  
      Args:
          cls_score (Tensor): Box score logits from the last decoder layer
              for each image. Shape [num_query, cls_out_channels].
          kpt_pred (Tensor): Sigmoid outputs from the last decoder layer
              for each image, with coordinate format (x_{i}, y_{i}) and
              shape [num_query, K*2].
          img_shape (tuple[int]): Shape of input image, (height, width, 3).
          scale_factor (ndarray, optional): Scale factor of the image arange
              as (w_scale, h_scale, w_scale, h_scale).
          rescale (bool, optional): If True, return boxes in original image
              space. Default False.
  
      Returns:
          tuple[Tensor]: Results of detected bboxes and labels.
  
              - det_bboxes: Predicted bboxes with shape [num_query, 5],
                  where the first 4 columns are bounding box positions
                  (tl_x, tl_y, br_x, br_y) and the 5-th column are scores
                  between 0 and 1.
              - det_labels: Predicted labels of the corresponding box with
                  shape [num_query].
              - det_kpts: Predicted keypoints with shape [num_query, K, 3].
      """
      assert len(cls_score) == len(kpt_pred)
      max_per_img = self.test_cfg.get("max_per_img", self.num_query)
      # exclude background
      if self.loss_cls.use_sigmoid:
          cls_score = F.sigmoid(cls_score)
          scores, indexs = cls_score.reshape([-1]).topk(max_per_img)
          det_labels = indexs % self.num_classes
          bbox_index = indexs // self.num_classes
          kpt_pred = kpt_pred[bbox_index]
      else:
          scores, det_labels = F.softmax(cls_score, axis=-1)[
              ..., :-1
          ].max(-1)
          scores, bbox_index = scores.topk(max_per_img)
          kpt_pred = kpt_pred[bbox_index]
          det_labels = det_labels[bbox_index]
  
      # ----- results after pose decoder -----
      # det_kpts = kpt_pred.reshape((kpt_pred.shape[0], -1, 2))
  
      # ----- results after joint decoder (default) -----
      # import time
      # start = time.time()
      refine_targets = (
          kpt_pred,
          None,
          None,
          paddle.ones_like(kpt_pred),
      )
      refine_outputs = self.forward_refine(
          memory, mlvl_masks, refine_targets, None, None
      )
      # end = time.time()
      # print(f'refine time: {end - start:.6f}')
      det_kpts = refine_outputs[-1]
  
      det_kpts[..., 0] = det_kpts[..., 0] * img_shape[1]
      det_kpts[..., 1] = det_kpts[..., 1] * img_shape[0]
      det_kpts[..., 0].clip_(min=0, max=img_shape[1])
      det_kpts[..., 1].clip_(min=0, max=img_shape[0])
      if rescale:
          det_kpts /= (
              paddle.to_tensor(scale_factor[:2], dtype=det_kpts.dtype)
              .unsqueeze(0)
              .unsqueeze(0)
          )
  
      # use circumscribed rectangle box of keypoints as det bboxes
      x1 = det_kpts[..., 0].min(axis=1, keepdim=True)
      y1 = det_kpts[..., 1].min(axis=1, keepdim=True)
      x2 = det_kpts[..., 0].max(axis=1, keepdim=True)
      y2 = det_kpts[..., 1].max(axis=1, keepdim=True)
      det_bboxes = paddle.concat([x1, y1, x2, y2], axis=1)
      det_bboxes = paddle.concat((det_bboxes, scores.unsqueeze(1)), -1)
  
      det_kpts = paddle.concat(
          (
              det_kpts,
              paddle.ones(
                  det_kpts[..., :1].shape, dtype=det_kpts.dtype
              ),
          ),
          axis=2,
      )
  
      return det_bboxes, det_labels, det_kpts
  
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 14 for calling the PETRHead obj's underlying member method code with example usage: obj._get_bboxes_single(cls_score, kpt_pred, img_shape, scale_factor, memory, mlvl_masks, rescale) and returns: det_bboxes,  det_labels,  det_kpts