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 batch of output features extracted from the head into
  bbox results.
  
  Args:
      all_layers_cls_scores (Tensor):  Classification scores of all
          decoder layers, has shape (num_decoder_layers, bs, num_queries,
          cls_out_channels).
      all_layers_bbox_preds (Tensor): Regression outputs of all decoder
          layers. Each is a 4D-tensor with normalized coordinate format
          (cx, cy, w, h) and shape (num_decoder_layers, bs, num_queries,
          4) with the last dimension arranged as (cx, cy, w, h).
      batch_img_metas (List[Dict]): _description_
      batch_token_positive_maps (list[dict], Optional): Batch token
          positive map. Defaults to None.
      rescale (bool): If True, return boxes in original image space.
          Defaults to False.
  
  Returns:
      list[:obj:`InstanceData`]: Object 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","batch","of","output","features","extracted","from","the","head","into","bbox","results",".","Args",":","all_layers_cls_scores","(","Tensor",")",":","Classification","scores","of","all","decoder","layers",",","has","shape","(","num_decoder_layers",",","bs",",","num_queries",",","cls_out_channels",")",".","all_layers_bbox_preds","(","Tensor",")",":","Regression","outputs","of","all","decoder","layers",".","Each","is","a","4D-tensor","with","normalized","coordinate","format","(","cx",",","cy",",","w",",","h",")","and","shape","(","num_decoder_layers",",","bs",",","num_queries",",","4",")","with","the","last","dimension","arranged","as","(","cx",",","cy",",","w",",","h",")",".","batch_img_metas","(","List","[","Dict","]",")",":","_description_","batch_token_positive_maps","(","list","[","dict","]",",","Optional",")",":","Batch","token","positive","map",".","Defaults","to","None",".","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Defaults","to","False",".","Returns",":","list","[",":","obj",":","`","InstanceData","`","]",":","Object","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(
      self,
      all_layers_cls_scores: Tensor,
      all_layers_bbox_preds: Tensor,
      batch_img_metas: List[Dict],
      batch_token_positive_maps: Optional[List[dict]] = None,
      rescale: bool = False,
  ) -> InstanceList:
      """Transform a batch of output features extracted from the head into
      bbox results.
  
      Args:
          all_layers_cls_scores (Tensor):  Classification scores of all
              decoder layers, has shape (num_decoder_layers, bs, num_queries,
              cls_out_channels).
          all_layers_bbox_preds (Tensor): Regression outputs of all decoder
              layers. Each is a 4D-tensor with normalized coordinate format
              (cx, cy, w, h) and shape (num_decoder_layers, bs, num_queries,
              4) with the last dimension arranged as (cx, cy, w, h).
          batch_img_metas (List[Dict]): _description_
          batch_token_positive_maps (list[dict], Optional): Batch token
              positive map. Defaults to None.
          rescale (bool): If True, return boxes in original image space.
              Defaults to False.
  
      Returns:
          list[:obj:`InstanceData`]: Object 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).
      """
      cls_scores = all_layers_cls_scores[-1]
      bbox_preds = all_layers_bbox_preds[-1]
      result_list = []
      for img_id in range(len(batch_img_metas)):
          cls_score = cls_scores[img_id]
          bbox_pred = bbox_preds[img_id]
          img_meta = batch_img_metas[img_id]
          token_positive_maps = batch_token_positive_maps[img_id]
          results = self._predict_by_feat_single(
              cls_score,
              bbox_pred,
              token_positive_maps,
              img_meta,
              rescale,
          )
          result_list.append(results)
      return result_list
  
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 7 for calling the GroundingDINOHead obj's underlying member method code with example usage: obj.predict_by_feat(all_layers_cls_scores, all_layers_bbox_preds, batch_img_metas, batch_token_positive_maps, rescale) and returns: result_list