class_docstr: Implementation of `GLIP <https://arxiv.org/abs/2112.03857>`_
  Args:
      backbone (:obj:`ConfigDict` or dict): The backbone config.
      neck (:obj:`ConfigDict` or dict): The neck config.
      bbox_head (:obj:`ConfigDict` or dict): The bbox head config.
      language_model (:obj:`ConfigDict` or dict): The language model config.
      train_cfg (:obj:`ConfigDict` or dict, optional): The training config
          of GLIP. Defaults to None.
      test_cfg (:obj:`ConfigDict` or dict, optional): The testing config
          of GLIP. Defaults to None.
      data_preprocessor (:obj:`ConfigDict` or dict, optional): Config of
          :class:`DetDataPreprocessor` to process the input data.
          Defaults to None.
      init_cfg (:obj:`ConfigDict` or list[:obj:`ConfigDict`] or dict or
          list[dict], optional): Initialization config dict.
          Defaults to None.
class_docstr_tok: ["Implementation","of","`","GLIP","<","https",":","\/\/arxiv.org\/abs\/2112.03857",">","`","_","Args",":","backbone","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","The","backbone","config",".","neck","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","The","neck","config",".","bbox_head","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","The","bbox","head","config",".","language_model","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","The","language","model","config",".","train_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","The","training","config","of","GLIP",".","Defaults","to","None",".","test_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","The","testing","config","of","GLIP",".","Defaults","to","None",".","data_preprocessor","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","of",":","class",":","`","DetDataPreprocessor","`","to","process","the","input","data",".","Defaults","to","None",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","list","[",":","obj",":","`","ConfigDict","`","]","or","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict",".","Defaults","to","None","."]
code: def loss(
      self, batch_inputs: Tensor, batch_data_samples: SampleList
  ) -> Union[dict, list]:
      # TODO: Only open vocabulary tasks are supported for training now.
      text_prompts = [
          data_samples.text for data_samples in batch_data_samples
      ]
  
      gt_labels = [
          data_samples.gt_instances.labels
          for data_samples in batch_data_samples
      ]
  
      new_text_prompts = []
      positive_maps = []
      if len(set(text_prompts)) == 1:
          # All the text prompts are the same,
          # so there is no need to calculate them multiple times.
          (
              tokenized,
              caption_string,
              tokens_positive,
              _,
          ) = self.get_tokens_and_prompts(text_prompts[0], True)
          new_text_prompts = [caption_string] * len(batch_inputs)
          for gt_label in gt_labels:
              new_tokens_positive = [
                  tokens_positive[label] for label in gt_label
              ]
              _, positive_map = self.get_positive_map(
                  tokenized, new_tokens_positive
              )
              positive_maps.append(positive_map)
      else:
          for text_prompt, gt_label in zip(text_prompts, gt_labels):
              (
                  tokenized,
                  caption_string,
                  tokens_positive,
                  _,
              ) = self.get_tokens_and_prompts(text_prompt, True)
              new_tokens_positive = [
                  tokens_positive[label] for label in gt_label
              ]
              _, positive_map = self.get_positive_map(
                  tokenized, new_tokens_positive
              )
              positive_maps.append(positive_map)
              new_text_prompts.append(caption_string)
  
      language_dict_features = self.language_model(new_text_prompts)
      for i, data_samples in enumerate(batch_data_samples):
          # .bool().float() is very important
          positive_map = (
              positive_maps[i].to(batch_inputs.device).bool().float()
          )
          data_samples.gt_instances.positive_maps = positive_map
  
      visual_features = self.extract_feat(batch_inputs)
  
      losses = self.bbox_head.loss(
          visual_features, language_dict_features, batch_data_samples
      )
      return losses
  
imports: import copy
  import re
  import warnings
  from typing import Optional, Tuple, Union
  import torch
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.utils import ConfigType, OptConfigType, OptMultiConfig
  from .single_stage import SingleStageDetector
label_desc: Use image node_id 8 for calling the GLIP obj's underlying member method code with example usage: obj.loss(batch_inputs, batch_data_samples) and returns: losses