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: Perform forward propagation and loss calculation of the detection
  head on the queries of the upstream network.
  
  Args:
      hidden_states (Tensor): Hidden states output from each decoder
          layer, has shape (num_decoder_layers, num_queries, bs, dim).
      references (List[Tensor]): List of the reference from the decoder.
          The first reference is the `init_reference` (initial) and the
          other num_decoder_layers(6) references are `inter_references`
          (intermediate). The `init_reference` has shape (bs,
          num_queries, 4) when `as_two_stage` of the detector is `True`,
          otherwise (bs, num_queries, 2). Each `inter_reference` has
          shape (bs, num_queries, 4) when `with_box_refine` of the
          detector is `True`, otherwise (bs, num_queries, 2). The
          coordinates are arranged as (cx, cy) when the last dimension is
          2, and (cx, cy, w, h) when it is 4.
      memory_text (Tensor): Memory text. It has shape (bs, len_text,
          text_embed_dims).
      text_token_mask (Tensor): Text token mask. It has shape (bs,
          len_text).
      batch_data_samples (SampleList): The Data
          Samples. It usually includes information such as
          `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
      rescale (bool, optional): If `True`, return boxes in original
          image space. Defaults to `True`.
  
  Returns:
      InstanceList: Detection results of each image
          after the post process.
docstr_tok: ["Perform","forward","propagation","and","loss","calculation","of","the","detection","head","on","the","queries","of","the","upstream","network",".","Args",":","hidden_states","(","Tensor",")",":","Hidden","states","output","from","each","decoder","layer",",","has","shape","(","num_decoder_layers",",","num_queries",",","bs",",","dim",")",".","references","(","List","[","Tensor","]",")",":","List","of","the","reference","from","the","decoder",".","The","first","reference","is","the","`","init_reference","`","(","initial",")","and","the","other","num_decoder_layers","(","6",")","references","are","`","inter_references","`","(","intermediate",")",".","The","`","init_reference","`","has","shape","(","bs",",","num_queries",",","4",")","when","`","as_two_stage","`","of","the","detector","is","`","True","`",",","otherwise","(","bs",",","num_queries",",","2",")",".","Each","`","inter_reference","`","has","shape","(","bs",",","num_queries",",","4",")","when","`","with_box_refine","`","of","the","detector","is","`","True","`",",","otherwise","(","bs",",","num_queries",",","2",")",".","The","coordinates","are","arranged","as","(","cx",",","cy",")","when","the","last","dimension","is","2",",","and","(","cx",",","cy",",","w",",","h",")","when","it","is","4.","memory_text","(","Tensor",")",":","Memory","text",".","It","has","shape","(","bs",",","len_text",",","text_embed_dims",")",".","text_token_mask","(","Tensor",")",":","Text","token","mask",".","It","has","shape","(","bs",",","len_text",")",".","batch_data_samples","(","SampleList",")",":","The","Data","Samples",".","It","usually","includes","information","such","as","`","gt_instance","`",",","`","gt_panoptic_seg","`","and","`","gt_sem_seg","`",".","rescale","(","bool",",","optional",")",":","If","`","True","`",",","return","boxes","in","original","image","space",".","Defaults","to","`","True","`",".","Returns",":","InstanceList",":","Detection","results","of","each","image","after","the","post","process","."]
code: def predict(
      self,
      hidden_states: Tensor,
      references: List[Tensor],
      memory_text: Tensor,
      text_token_mask: Tensor,
      batch_data_samples: SampleList,
      rescale: bool = True,
  ) -> InstanceList:
      """Perform forward propagation and loss calculation of the detection
      head on the queries of the upstream network.
  
      Args:
          hidden_states (Tensor): Hidden states output from each decoder
              layer, has shape (num_decoder_layers, num_queries, bs, dim).
          references (List[Tensor]): List of the reference from the decoder.
              The first reference is the `init_reference` (initial) and the
              other num_decoder_layers(6) references are `inter_references`
              (intermediate). The `init_reference` has shape (bs,
              num_queries, 4) when `as_two_stage` of the detector is `True`,
              otherwise (bs, num_queries, 2). Each `inter_reference` has
              shape (bs, num_queries, 4) when `with_box_refine` of the
              detector is `True`, otherwise (bs, num_queries, 2). The
              coordinates are arranged as (cx, cy) when the last dimension is
              2, and (cx, cy, w, h) when it is 4.
          memory_text (Tensor): Memory text. It has shape (bs, len_text,
              text_embed_dims).
          text_token_mask (Tensor): Text token mask. It has shape (bs,
              len_text).
          batch_data_samples (SampleList): The Data
              Samples. It usually includes information such as
              `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
          rescale (bool, optional): If `True`, return boxes in original
              image space. Defaults to `True`.
  
      Returns:
          InstanceList: Detection results of each image
              after the post process.
      """
      batch_img_metas = [
          data_samples.metainfo for data_samples in batch_data_samples
      ]
      batch_token_positive_maps = [
          data_samples.token_positive_map
          for data_samples in batch_data_samples
      ]
  
      outs = self(
          hidden_states, references, memory_text, text_token_mask
      )
  
      predictions = self.predict_by_feat(
          *outs,
          batch_img_metas=batch_img_metas,
          batch_token_positive_maps=batch_token_positive_maps,
          rescale=rescale,
      )
      return predictions
  
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 6 for calling the GroundingDINOHead obj's underlying member method code with example usage: obj.predict(hidden_states, references, memory_text, text_token_mask, batch_data_samples, rescale) and returns: predictions