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.
  
  Args:
      mlvl_feats (tuple[Tensor]): Features from the upstream
          network, each is a 4D-tensor with shape
          (N, C, H, W).
      img_metas (list[dict]): List of image information.
  
  Returns:
      outputs_classes (Tensor): Outputs from the classification head,
          shape [nb_dec, bs, num_query, cls_out_channels]. Note
          cls_out_channels should include background.
      outputs_kpts (Tensor): Sigmoid outputs from the regression
          head with normalized coordinate format (cx, cy, w, h).
          Shape [nb_dec, bs, num_query, K*2].
      enc_outputs_class (Tensor): The score of each point on encode
          feature map, has shape (N, h*w, num_class). Only when
          as_two_stage is Ture it would be returned, otherwise
          `None` would be returned.
      enc_outputs_kpt (Tensor): The proposal generate from the
          encode feature map, has shape (N, h*w, K*2). Only when
          as_two_stage is Ture it would be returned, otherwise
          `None` would be returned.
docstr_tok: ["Forward","function",".","Args",":","mlvl_feats","(","tuple","[","Tensor","]",")",":","Features","from","the","upstream","network",",","each","is","a","4D-tensor","with","shape","(","N",",","C",",","H",",","W",")",".","img_metas","(","list","[","dict","]",")",":","List","of","image","information",".","Returns",":","outputs_classes","(","Tensor",")",":","Outputs","from","the","classification","head",",","shape","[","nb_dec",",","bs",",","num_query",",","cls_out_channels","]",".","Note","cls_out_channels","should","include","background",".","outputs_kpts","(","Tensor",")",":","Sigmoid","outputs","from","the","regression","head","with","normalized","coordinate","format","(","cx",",","cy",",","w",",","h",")",".","Shape","[","nb_dec",",","bs",",","num_query",",","K","*","2","]",".","enc_outputs_class","(","Tensor",")",":","The","score","of","each","point","on","encode","feature","map",",","has","shape","(","N",",","h","*","w",",","num_class",")",".","Only","when","as_two_stage","is","Ture","it","would","be","returned",",","otherwise","`","None","`","would","be","returned",".","enc_outputs_kpt","(","Tensor",")",":","The","proposal","generate","from","the","encode","feature","map",",","has","shape","(","N",",","h","*","w",",","K","*","2",")",".","Only","when","as_two_stage","is","Ture","it","would","be","returned",",","otherwise","`","None","`","would","be","returned","."]
code: def forward(self, mlvl_feats, img_metas):
      """Forward function.
  
      Args:
          mlvl_feats (tuple[Tensor]): Features from the upstream
              network, each is a 4D-tensor with shape
              (N, C, H, W).
          img_metas (list[dict]): List of image information.
  
      Returns:
          outputs_classes (Tensor): Outputs from the classification head,
              shape [nb_dec, bs, num_query, cls_out_channels]. Note
              cls_out_channels should include background.
          outputs_kpts (Tensor): Sigmoid outputs from the regression
              head with normalized coordinate format (cx, cy, w, h).
              Shape [nb_dec, bs, num_query, K*2].
          enc_outputs_class (Tensor): The score of each point on encode
              feature map, has shape (N, h*w, num_class). Only when
              as_two_stage is Ture it would be returned, otherwise
              `None` would be returned.
          enc_outputs_kpt (Tensor): The proposal generate from the
              encode feature map, has shape (N, h*w, K*2). Only when
              as_two_stage is Ture it would be returned, otherwise
              `None` would be returned.
      """
  
      batch_size = mlvl_feats[0].shape[0]
      input_img_h, input_img_w = img_metas[0]["batch_input_shape"]
      img_masks = paddle.zeros(
          (batch_size, input_img_h, input_img_w),
          dtype=mlvl_feats[0].dtype,
      )
      for img_id in range(batch_size):
          img_h, img_w, _ = img_metas[img_id]["img_shape"]
          img_masks[img_id, :img_h, :img_w] = 1
  
      mlvl_masks = []
      mlvl_positional_encodings = []
      for feat in mlvl_feats:
          mlvl_masks.append(
              F.interpolate(
                  img_masks[None], size=feat.shape[-2:]
              ).squeeze(0)
          )
          mlvl_positional_encodings.append(
              self.positional_encoding(mlvl_masks[-1]).transpose(
                  [0, 3, 1, 2]
              )
          )
  
      query_embeds = self.query_embedding.weight
      (
          hs,
          init_reference,
          inter_references,
          enc_outputs_class,
          enc_outputs_kpt,
          hm_proto,
          memory,
      ) = self.transformer(
          mlvl_feats,
          mlvl_masks,
          query_embeds,
          mlvl_positional_encodings,
          kpt_branches=self.kpt_branches
          if self.with_kpt_refine
          else None,  # noqa:E501
          cls_branches=self.cls_branches
          if self.as_two_stage
          else None,  # noqa:E501
      )
  
      outputs_classes = []
      outputs_kpts = []
  
      for lvl in range(hs.shape[0]):
          if lvl == 0:
              reference = init_reference
          else:
              reference = inter_references[lvl - 1]
          reference = inverse_sigmoid(reference)
          outputs_class = self.cls_branches[lvl](hs[lvl])
          tmp_kpt = self.kpt_branches[lvl](hs[lvl])
          assert reference.shape[-1] == self.num_keypoints * 2
          tmp_kpt += reference
          outputs_kpt = F.sigmoid(tmp_kpt)
          outputs_classes.append(outputs_class)
          outputs_kpts.append(outputs_kpt)
  
      outputs_classes = paddle.stack(outputs_classes)
      outputs_kpts = paddle.stack(outputs_kpts)
  
      if hm_proto is not None:
          # get heatmap prediction (training phase)
          hm_memory, hm_mask = hm_proto
          hm_pred = self.fc_hm(hm_memory)
          hm_proto = (hm_pred.transpose((0, 3, 1, 2)), hm_mask)
  
      if self.as_two_stage:
          return (
              outputs_classes,
              outputs_kpts,
              enc_outputs_class,
              F.sigmoid(enc_outputs_kpt),
              hm_proto,
              memory,
              mlvl_masks,
          )
      else:
          raise RuntimeError('only "as_two_stage=True" is supported.')
  
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 4 for calling the PETRHead obj's underlying member method code with example usage: obj.forward(mlvl_feats, img_metas) and returns: outputs_classes,  outputs_kpts,  enc_outputs_class,  F,  hm_proto,  memory,  mlvl_masks