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: Initialize layers except for backbone, neck and bbox_head.
docstr_tok: ["Initialize","layers","except","for","backbone",",","neck","and","bbox_head","."]
code: def _init_layers(self) -> None:
      """Initialize layers except for backbone, neck and bbox_head."""
      self.positional_encoding = SinePositionalEncoding(
          **self.positional_encoding
      )
      self.encoder = GroundingDinoTransformerEncoder(**self.encoder)
      self.decoder = GroundingDinoTransformerDecoder(**self.decoder)
      self.embed_dims = self.encoder.embed_dims
      self.query_embedding = nn.Embedding(
          self.num_queries, self.embed_dims
      )
      num_feats = self.positional_encoding.num_feats
      assert num_feats * 2 == self.embed_dims, (
          f"embed_dims should be exactly 2 times of num_feats. "
          f"Found {self.embed_dims} and {num_feats}."
      )
  
      self.level_embed = nn.Parameter(
          torch.Tensor(self.num_feature_levels, self.embed_dims)
      )
      self.memory_trans_fc = nn.Linear(self.embed_dims, self.embed_dims)
      self.memory_trans_norm = nn.LayerNorm(self.embed_dims)
  
      # text modules
      self.language_model = MODELS.build(self.language_model_cfg)
      self.text_feat_map = nn.Linear(
          self.language_model.language_backbone.body.language_dim,
          self.embed_dims,
          bias=True,
      )
  
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 2 for calling the GroundingDINO obj's underlying member method code with example usage: obj._init_layers() without return types