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: Forward with Transformer encoder.
  
  The forward procedure of the transformer is defined as:
  'pre_transformer' -> 'encoder' -> 'pre_decoder' -> 'decoder'
  More details can be found at `TransformerDetector.forward_transformer`
  in `mmdet/detector/base_detr.py`.
  
  Args:
      feat (Tensor): Sequential features, has shape (bs, num_feat_points,
          dim).
      feat_mask (Tensor): ByteTensor, the padding mask of the features,
          has shape (bs, num_feat_points).
      feat_pos (Tensor): The positional embeddings of the features, has
          shape (bs, num_feat_points, dim).
      spatial_shapes (Tensor): Spatial shapes of features in all levels,
          has shape (num_levels, 2), last dimension represents (h, w).
      level_start_index (Tensor): The start index of each level.
          A tensor has shape (num_levels, ) and can be represented
          as [0, h_0*w_0, h_0*w_0+h_1*w_1, ...].
      valid_ratios (Tensor): The ratios of the valid width and the valid
          height relative to the width and the height of features in all
          levels, has shape (bs, num_levels, 2).
  
  Returns:
      dict: The dictionary of encoder outputs, which includes the
      `memory` of the encoder output.
docstr_tok: ["Forward","with","Transformer","encoder",".","The","forward","procedure","of","the","transformer","is","defined","as",":","'pre_transformer","'","-",">","'encoder","'","-",">","'pre_decoder","'","-",">","'decoder'","More","details","can","be","found","at","`","TransformerDetector.forward_transformer","`","in","`","mmdet\/detector\/base_detr.py","`",".","Args",":","feat","(","Tensor",")",":","Sequential","features",",","has","shape","(","bs",",","num_feat_points",",","dim",")",".","feat_mask","(","Tensor",")",":","ByteTensor",",","the","padding","mask","of","the","features",",","has","shape","(","bs",",","num_feat_points",")",".","feat_pos","(","Tensor",")",":","The","positional","embeddings","of","the","features",",","has","shape","(","bs",",","num_feat_points",",","dim",")",".","spatial_shapes","(","Tensor",")",":","Spatial","shapes","of","features","in","all","levels",",","has","shape","(","num_levels",",","2",")",",","last","dimension","represents","(","h",",","w",")",".","level_start_index","(","Tensor",")",":","The","start","index","of","each","level",".","A","tensor","has","shape","(","num_levels",",",")","and","can","be","represented","as","[","0",",","h_0","*","w_0",",","h_0","*","w_0+h_1","*","w_1",",","...","]",".","valid_ratios","(","Tensor",")",":","The","ratios","of","the","valid","width","and","the","valid","height","relative","to","the","width","and","the","height","of","features","in","all","levels",",","has","shape","(","bs",",","num_levels",",","2",")",".","Returns",":","dict",":","The","dictionary","of","encoder","outputs",",","which","includes","the","`","memory","`","of","the","encoder","output","."]
code: def forward_encoder(
      self,
      feat: Tensor,
      feat_mask: Tensor,
      feat_pos: Tensor,
      spatial_shapes: Tensor,
      level_start_index: Tensor,
      valid_ratios: Tensor,
  ) -> Dict:
      """Forward with Transformer encoder.
  
      The forward procedure of the transformer is defined as:
      'pre_transformer' -> 'encoder' -> 'pre_decoder' -> 'decoder'
      More details can be found at `TransformerDetector.forward_transformer`
      in `mmdet/detector/base_detr.py`.
  
      Args:
          feat (Tensor): Sequential features, has shape (bs, num_feat_points,
              dim).
          feat_mask (Tensor): ByteTensor, the padding mask of the features,
              has shape (bs, num_feat_points).
          feat_pos (Tensor): The positional embeddings of the features, has
              shape (bs, num_feat_points, dim).
          spatial_shapes (Tensor): Spatial shapes of features in all levels,
              has shape (num_levels, 2), last dimension represents (h, w).
          level_start_index (Tensor): The start index of each level.
              A tensor has shape (num_levels, ) and can be represented
              as [0, h_0*w_0, h_0*w_0+h_1*w_1, ...].
          valid_ratios (Tensor): The ratios of the valid width and the valid
              height relative to the width and the height of features in all
              levels, has shape (bs, num_levels, 2).
  
      Returns:
          dict: The dictionary of encoder outputs, which includes the
          `memory` of the encoder output.
      """
      memory = self.encoder(
          query=feat,
          query_pos=feat_pos,
          key_padding_mask=feat_mask,  # for self_attn
          spatial_shapes=spatial_shapes,
          level_start_index=level_start_index,
          valid_ratios=valid_ratios,
      )
      encoder_outputs_dict = dict(
          memory=memory,
          memory_mask=feat_mask,
          spatial_shapes=spatial_shapes,
      )
      return encoder_outputs_dict
  
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 5 for calling the DeformableDETR obj's underlying member method code with example usage: obj.forward_encoder(feat, feat_mask, feat_pos, spatial_shapes, level_start_index, valid_ratios) and returns: encoder_outputs_dict