class_docstr: Implementation of `Grounding DINO: Marrying DINO with Grounded Pre-
  Training for Open-Set Object Detection.
  
  <https://arxiv.org/abs/2303.05499>`_
  
  Code is modified from the `official github repo
  <https://github.com/IDEA-Research/GroundingDINO>`_.
class_docstr_tok: ["Implementation","of","`","Grounding","DINO",":","Marrying","DINO","with","Grounded","Pre-","Training","for","Open-Set","Object","Detection",".","<","https",":","\/\/arxiv.org\/abs\/2303.05499",">","`","_","Code","is","modified","from","the","`","official","github","repo","<","https",":","\/\/github.com\/IDEA-Research\/GroundingDINO",">","`","_","."]
docstr: Get the tokens positive and prompts for the caption.
docstr_tok: ["Get","the","tokens","positive","and","prompts","for","the","caption","."]
code: def get_tokens_and_prompts(
      self,
      original_caption: Union[str, list, tuple],
      custom_entities: bool = False,
      enhanced_text_prompts: Optional[ConfigType] = None,
  ) -> Tuple[dict, str, list]:
      """Get the tokens positive and prompts for the caption."""
      if isinstance(original_caption, (list, tuple)) or custom_entities:
          if custom_entities and isinstance(original_caption, str):
              original_caption = original_caption.strip(
                  self._special_tokens
              )
              original_caption = original_caption.split(
                  self._special_tokens
              )
              original_caption = list(
                  filter(lambda x: len(x) > 0, original_caption)
              )
  
          original_caption = [
              clean_label_name(i) for i in original_caption
          ]
  
          if custom_entities and enhanced_text_prompts is not None:
              (
                  caption_string,
                  tokens_positive,
              ) = self.to_enhance_text_prompts(
                  original_caption, enhanced_text_prompts
              )
          else:
              (
                  caption_string,
                  tokens_positive,
              ) = self.to_plain_text_prompts(original_caption)
  
          # NOTE: Tokenizer in Grounding DINO is different from
          # that in GLIP. The tokenizer in GLIP will pad the
          # caption_string to max_length, while the tokenizer
          # in Grounding DINO will not.
          tokenized = self.language_model.tokenizer(
              [caption_string],
              padding="max_length"
              if self.language_model.pad_to_max
              else "longest",
              return_tensors="pt",
          )
          entities = original_caption
      else:
          if not original_caption.endswith("."):
              original_caption = original_caption + self._special_tokens
          # NOTE: Tokenizer in Grounding DINO is different from
          # that in GLIP. The tokenizer in GLIP will pad the
          # caption_string to max_length, while the tokenizer
          # in Grounding DINO will not.
          tokenized = self.language_model.tokenizer(
              [original_caption],
              padding="max_length"
              if self.language_model.pad_to_max
              else "longest",
              return_tensors="pt",
          )
          tokens_positive, noun_phrases = run_ner(original_caption)
          entities = noun_phrases
          caption_string = original_caption
  
      return tokenized, caption_string, tokens_positive, entities
  
imports: import copy
  import re
  import warnings
  from typing import Dict, Optional, Tuple, Union
  import torch
  import torch.nn
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import OptSampleList, SampleList
  from mmdet.utils import ConfigType
  from ..layers import SinePositionalEncoding
  from ..layers.transformer.grounding_dino_layers import GroundingDinoTransformerDecoder, GroundingDinoTransformerEncoder
  from .dino import DINO
  from .glip import create_positive_map, create_positive_map_label_to_token, run_ner
label_desc: Use image node_id 6 for calling the GroundingDINO obj's underlying member method code with example usage: obj.get_tokens_and_prompts(original_caption, custom_entities, enhanced_text_prompts) and returns: tokenized,  caption_string,  tokens_positive,  entities