class_docstr: Implements the DETR transformer head.
  
  See `paper: End-to-End Object Detection with Transformers
  <https://arxiv.org/pdf/2005.12872>`_ for details.
  
  Args:
      num_classes (int): Number of categories excluding the background.
      in_channels (int): Number of channels in the input feature map.
      num_fcs (int, optional): Number of fully-connected layers used in
          `FFN`, which is then used for the regression head. Default 2.
      transformer (dict, optional): Config for transformer.
      positional_encoding (dict, optional): Config for position encoding.
      loss_cls (dict, optional): Config of the classification loss.
          Default `CrossEntropyLoss`.
      loss_bbox (dict, optional): Config of the regression loss.
          Default `L1Loss`.
      loss_iou (dict, optional): Config of the regression iou loss.
          Default `GIoULoss`.
      tran_cfg (dict, optional): Training config of transformer head.
      test_cfg (dict, optional): Testing config of transformer head.
  
  Example:
      >>> import torch
      >>> self = TransformerHead(80, 2048)
      >>> x = torch.rand(1, 2048, 32, 32)
      >>> mask = torch.ones(1, 32, 32).to(x.dtype)
      >>> mask[:, :16, :15] = 0
      >>> all_cls_scores, all_bbox_preds = self(x, mask)
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].
      bbox_pred (Tensor): Sigmoid outputs from the last decoder layer
          for each image, with coordinate format (cx, cy, w, h) and
          shape [num_query, 4].
      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].
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","]",".","bbox_pred","(","Tensor",")",":","Sigmoid","outputs","from","the","last","decoder","layer","for","each","image",",","with","coordinate","format","(","cx",",","cy",",","w",",","h",")","and","shape","[","num_query",",","4","]",".","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","]","."]
code: def _get_bboxes_single(
      self, cls_score, bbox_pred, img_shape, scale_factor, 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].
              bbox_pred (Tensor): Sigmoid outputs from the last decoder layer
                  for each image, with coordinate format (cx, cy, w, h) and
                  shape [num_query, 4].
              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].
          """
      assert len(cls_score) == len(bbox_pred)
      # exclude background
      scores, det_labels = F.softmax(cls_score, dim=-1)[..., :-1].max(
          -1
      )
      det_bboxes = bbox_cxcywh_to_xyxy(bbox_pred)
      det_bboxes[:, 0::2] = det_bboxes[:, 0::2] * img_shape[1]
      det_bboxes[:, 1::2] = det_bboxes[:, 1::2] * img_shape[0]
      det_bboxes[:, 0::2].clamp_(min=0, max=img_shape[1])
      det_bboxes[:, 1::2].clamp_(min=0, max=img_shape[0])
      if rescale:
          det_bboxes /= det_bboxes.new_tensor(scale_factor)
      det_bboxes = torch.cat((det_bboxes, scores.unsqueeze(1)), -1)
      return det_bboxes, det_labels
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Conv2d, Linear, build_activation_layer
  from mmcv.runner import force_fp32
  from mmdet.core import bbox_cxcywh_to_xyxy, bbox_xyxy_to_cxcywh, build_assigner, build_sampler, multi_apply, reduce_mean
  from mmdet.models.utils import FFN, build_positional_encoding, build_transformer
  from ..builder import HEADS, build_loss
  from .anchor_free_head import AnchorFreeHead
label_desc: Use image node_id 13 for calling the TransformerHead obj's underlying member method code with example usage: obj._get_bboxes_single(cls_score, bbox_pred, img_shape, scale_factor, rescale) and returns: det_bboxes,  det_labels