class_docstr: Head of the Grounding DINO: Marrying DINO with Grounded Pre-Training for
  Open-Set Object Detection.
  
  Args:
      contrastive_cfg (dict, optional): Contrastive config that contains
        keys like ``max_text_len``. Defaults to dict(max_text_len=256).
class_docstr_tok: ["Head","of","the","Grounding","DINO",":","Marrying","DINO","with","Grounded","Pre-Training","for","Open-Set","Object","Detection",".","Args",":","contrastive_cfg","(","dict",",","optional",")",":","Contrastive","config","that","contains","keys","like","``","max_text_len","``",".","Defaults","to","dict","(","max_text_len=256",")","."]
docstr: Transform a single image's features extracted from the head into
  bbox results.
  
  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].
      token_positive_maps (dict): Token positive map.
      img_meta (dict): Image meta info.
      rescale (bool, optional): 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","a","single","image","'s","features","extracted","from","the","head","into","bbox","results",".","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","]",".","token_positive_maps","(","dict",")",":","Token","positive","map",".","img_meta","(","dict",")",":","Image","meta","info",".","rescale","(","bool",",","optional",")",":","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,
      token_positive_maps: dict,
      img_meta: dict,
      rescale: bool = True,
  ) -> InstanceData:
      """Transform a single image's features extracted from the head into
      bbox results.
  
      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].
          token_positive_maps (dict): Token positive map.
          img_meta (dict): Image meta info.
          rescale (bool, optional): 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"]
  
      if token_positive_maps is not None:
          cls_score = convert_grounding_to_cls_scores(
              logits=cls_score.sigmoid()[None],
              positive_maps=[token_positive_maps],
          )[0]
          scores, indexes = cls_score.view(-1).topk(max_per_img)
          num_classes = cls_score.shape[-1]
          det_labels = indexes % num_classes
          bbox_index = indexes // num_classes
          bbox_pred = bbox_pred[bbox_index]
      else:
          cls_score = cls_score.sigmoid()
          scores, _ = cls_score.max(-1)
          scores, indexes = scores.topk(max_per_img)
          bbox_pred = bbox_pred[indexes]
          det_labels = scores.new_zeros(scores.shape, dtype=torch.long)
  
      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: import copy
  import math
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  import torch.nn
  from mmcv.cnn import Linear
  from mmengine.model import constant_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.losses import QualityFocalLoss
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox_cxcywh_to_xyxy, bbox_xyxy_to_cxcywh
  from mmdet.utils import InstanceList, reduce_mean
  from ..layers import inverse_sigmoid
  from .atss_vlfusion_head import convert_grounding_to_cls_scores
  from .dino_head import DINOHead
label_desc: Use image node_id 8 for calling the GroundingDINOHead obj's underlying member method code with example usage: obj._predict_by_feat_single(cls_score, bbox_pred, token_positive_maps, img_meta, rescale) and returns: results