class_docstr: Implementation of `Deformable DETR: Deformable Transformers for
  End-to-End Object Detection <https://arxiv.org/abs/2010.04159>`_
  
  Code is modified from the `official github repo
  <https://github.com/fundamentalvision/Deformable-DETR>`_.
  
  Args:
      decoder (:obj:`ConfigDict` or dict, optional): Config of the
          Transformer decoder. Defaults to None.
      bbox_head (:obj:`ConfigDict` or dict, optional): Config for the
          bounding box head module. Defaults to None.
      with_box_refine (bool, optional): Whether to refine the references
          in the decoder. Defaults to `False`.
      as_two_stage (bool, optional): Whether to generate the proposal
          from the outputs of encoder. Defaults to `False`.
      num_feature_levels (int, optional): Number of feature levels.
          Defaults to 4.
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 = DeformableDetrTransformerEncoder(**self.encoder)
      self.decoder = DeformableDetrTransformerDecoder(**self.decoder)
      self.embed_dims = self.encoder.embed_dims
      if not self.as_two_stage:
          self.query_embedding = nn.Embedding(
              self.num_queries, self.embed_dims * 2
          )
          # NOTE The query_embedding will be split into query and query_pos
          # in self.pre_decoder, hence, the embed_dims are doubled.
  
      num_feats = self.positional_encoding.num_feats
      assert num_feats * 2 == self.embed_dims, (
          "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)
      )
  
      if self.as_two_stage:
          self.memory_trans_fc = nn.Linear(
              self.embed_dims, self.embed_dims
          )
          self.memory_trans_norm = nn.LayerNorm(self.embed_dims)
          self.pos_trans_fc = nn.Linear(
              self.embed_dims * 2, self.embed_dims * 2
          )
          self.pos_trans_norm = nn.LayerNorm(self.embed_dims * 2)
      else:
          self.reference_points_fc = nn.Linear(self.embed_dims, 2)
  
imports: import math
  from typing import Dict, Tuple
  import torch
  import torch.nn.functional
  from mmcv.cnn.bricks.transformer import MultiScaleDeformableAttention
  from mmengine.model import xavier_init
  from torch import Tensor, nn
  from torch.nn.init import normal_
  from mmdet.registry import MODELS
  from mmdet.structures import OptSampleList
  from mmdet.utils import OptConfigType
  from ..layers import DeformableDetrTransformerDecoder, DeformableDetrTransformerEncoder, SinePositionalEncoding
  from .base_detr import DetectionTransformer
label_desc: Use image node_id 2 for calling the DeformableDETR obj's underlying member method code with example usage: obj._init_layers() without return types