class_docstr: Head of DETR. DETR:End-to-End Object Detection with Transformers.
  
  More details can be found in the `paper
  <https://arxiv.org/pdf/2005.12872>`_ .
  
  Args:
      num_classes (int): Number of categories excluding the background.
      embed_dims (int): The dims of Transformer embedding.
      num_reg_fcs (int): Number of fully-connected layers used in `FFN`,
          which is then used for the regression head. Defaults to 2.
      sync_cls_avg_factor (bool): Whether to sync the `avg_factor` of
          all ranks. Default to `False`.
      loss_cls (:obj:`ConfigDict` or dict): Config of the classification
          loss. Defaults to `CrossEntropyLoss`.
      loss_bbox (:obj:`ConfigDict` or dict): Config of the regression bbox
          loss. Defaults to `L1Loss`.
      loss_iou (:obj:`ConfigDict` or dict): Config of the regression iou
          loss. Defaults to `GIoULoss`.
      train_cfg (:obj:`ConfigDict` or dict): Training config of transformer
          head.
      test_cfg (:obj:`ConfigDict` or dict): Testing config of transformer
          head.
      init_cfg (:obj:`ConfigDict` or dict, optional): the config to control
          the initialization. Defaults to 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_queries, 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_queries, 4].
      img_meta (dict): Image meta info.
      rescale (bool): If True, return boxes in original image
          space. Default True.
  
  Returns:
      :obj:`InstanceData`: Detection results of each image
      after the post process.
      Each item usually contains following keys.
  
          - scores (Tensor): Classification scores, has a shape
            (num_instance, )
          - labels (Tensor): Labels of bboxes, has a shape
            (num_instances, ).
          - bboxes (Tensor): Has a shape (num_instances, 4),
            the last dimension 4 arrange as (x1, y1, x2, y2).
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_queries",",","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_queries",",","4","]",".","img_meta","(","dict",")",":","Image","meta","info",".","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Default","True",".","Returns",":",":","obj",":","`","InstanceData","`",":","Detection","results","of","each","image","after","the","post","process",".","Each","item","usually","contains","following","keys",".","-","scores","(","Tensor",")",":","Classification","scores",",","has","a","shape","(","num_instance",",",")","-","labels","(","Tensor",")",":","Labels","of","bboxes",",","has","a","shape","(","num_instances",",",")",".","-","bboxes","(","Tensor",")",":","Has","a","shape","(","num_instances",",","4",")",",","the","last","dimension","4","arrange","as","(","x1",",","y1",",","x2",",","y2",")","."]
code: def _predict_by_feat_single(
      self,
      cls_score: Tensor,
      bbox_pred: Tensor,
      img_meta: dict,
      rescale: bool = True,
  ) -> InstanceData:
      """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_queries, 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_queries, 4].
          img_meta (dict): Image meta info.
          rescale (bool): If True, return boxes in original image
              space. Default True.
  
      Returns:
          :obj:`InstanceData`: Detection results of each image
          after the post process.
          Each item usually contains following keys.
  
              - scores (Tensor): Classification scores, has a shape
                (num_instance, )
              - labels (Tensor): Labels of bboxes, has a shape
                (num_instances, ).
              - bboxes (Tensor): Has a shape (num_instances, 4),
                the last dimension 4 arrange as (x1, y1, x2, y2).
      """
      assert len(cls_score) == len(bbox_pred)  # num_queries
      max_per_img = self.test_cfg.get("max_per_img", len(cls_score))
      img_shape = img_meta["img_shape"]
      # exclude background
      if self.loss_cls.use_sigmoid:
          cls_score = cls_score.sigmoid()
          scores, indexes = cls_score.view(-1).topk(max_per_img)
          det_labels = indexes % self.num_classes
          bbox_index = indexes // self.num_classes
          bbox_pred = bbox_pred[bbox_index]
      else:
          scores, det_labels = F.softmax(cls_score, dim=-1)[
              ..., :-1
          ].max(-1)
          scores, bbox_index = scores.topk(max_per_img)
          bbox_pred = bbox_pred[bbox_index]
          det_labels = det_labels[bbox_index]
  
      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:
          assert img_meta.get("scale_factor") is not None
          det_bboxes /= det_bboxes.new_tensor(
              img_meta["scale_factor"]
          ).repeat((1, 2))
  
      results = InstanceData()
      results.bboxes = det_bboxes
      results.scores = scores
      results.labels = det_labels
      return results
  
imports: from typing import Dict, List, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Linear
  from mmcv.cnn.bricks.transformer import FFN
  from mmengine.model import BaseModule
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox_cxcywh_to_xyxy, bbox_overlaps, bbox_xyxy_to_cxcywh
  from mmdet.utils import ConfigType, InstanceList, OptInstanceList, OptMultiConfig, reduce_mean
  from ..losses import QualityFocalLoss
  from ..utils import multi_apply
label_desc: Use image node_id 12 for calling the DETRHead obj's underlying member method code with example usage: obj._predict_by_feat_single(cls_score, bbox_pred, img_meta, rescale) and returns: results