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.
code: def __init__(
      self,
      *args,
      decoder: OptConfigType = None,
      bbox_head: OptConfigType = None,
      with_box_refine: bool = False,
      as_two_stage: bool = False,
      num_feature_levels: int = 4,
      **kwargs,
  ) -> None:
      self.with_box_refine = with_box_refine
      self.as_two_stage = as_two_stage
      self.num_feature_levels = num_feature_levels
  
      if bbox_head is not None:
          assert (
              "share_pred_layer" not in bbox_head
              and "num_pred_layer" not in bbox_head
              and "as_two_stage" not in bbox_head
          ), (
              "The two keyword args `share_pred_layer`, `num_pred_layer`, "
              "and `as_two_stage are set in `detector.__init__()`, users "
              "should not set them in `bbox_head` config."
          )
          # The last prediction layer is used to generate proposal
          # from encode feature map when `as_two_stage` is `True`.
          # And all the prediction layers should share parameters
          # when `with_box_refine` is `True`.
          bbox_head["share_pred_layer"] = not with_box_refine
          bbox_head["num_pred_layer"] = (
              (decoder["num_layers"] + 1)
              if self.as_two_stage
              else decoder["num_layers"]
          )
          bbox_head["as_two_stage"] = as_two_stage
  
      super().__init__(
          *args, decoder=decoder, bbox_head=bbox_head, **kwargs
      )
  
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 1 to create a new DeformableDETR object from inherited base classes: DetectionTransformer with example: obj = DeformableDETR()