class_docstr: Implements the DeformableDETR transformer.
  
  Args:
      as_two_stage (bool): Generate query from encoder features.
          Default: False.
      num_feature_levels (int): Number of feature maps from FPN:
          Default: 4.
      two_stage_num_proposals (int): Number of proposals when set
          `as_two_stage` as True. Default: 300.
class_docstr_tok: ["Implements","the","DeformableDETR","transformer",".","Args",":","as_two_stage","(","bool",")",":","Generate","query","from","encoder","features",".","Default",":","False",".","num_feature_levels","(","int",")",":","Number","of","feature","maps","from","FPN",":","Default",":","4.","two_stage_num_proposals","(","int",")",":","Number","of","proposals","when","set","`","as_two_stage","`","as","True",".","Default",":","300","."]
docstr: Get the reference points used in decoder.
  
  Args:
      spatial_shapes (Tensor): The shape of all
          feature maps, has shape (num_level, 2).
      valid_ratios (Tensor): The radios of valid
          points on the feature map, has shape
          (bs, num_levels, 2)
      device (obj:`device`): The device where
          reference_points should be.
  
  Returns:
      Tensor: reference points used in decoder, has                 shape (bs, num_keys, num_levels, 2).
code: def get_reference_points(spatial_shapes, valid_ratios, device):
      """Get the reference points used in decoder.
  
          Args:
              spatial_shapes (Tensor): The shape of all
                  feature maps, has shape (num_level, 2).
              valid_ratios (Tensor): The radios of valid
                  points on the feature map, has shape
                  (bs, num_levels, 2)
              device (obj:`device`): The device where
                  reference_points should be.
  
          Returns:
              Tensor: reference points used in decoder, has \
                  shape (bs, num_keys, num_levels, 2).
          """
      reference_points_list = []
      for lvl, (H, W) in enumerate(spatial_shapes):
          ref_y, ref_x = torch.meshgrid(
              torch.linspace(
                  0.5, H - 0.5, H, dtype=torch.float32, device=device
              ),
              torch.linspace(
                  0.5, W - 0.5, W, dtype=torch.float32, device=device
              ),
          )
          ref_y = ref_y.reshape(-1)[None] / (
              valid_ratios[:, None, lvl, 1] * H
          )
          ref_x = ref_x.reshape(-1)[None] / (
              valid_ratios[:, None, lvl, 0] * W
          )
          ref = torch.stack((ref_x, ref_y), -1)
          reference_points_list.append(ref)
      reference_points = torch.cat(reference_points_list, 1)
      reference_points = (
          reference_points[:, :, None] * valid_ratios[:, None]
      )
      return reference_points
  
imports: import math
  import warnings
  from typing import Sequence
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from mmcv.cnn import Linear, build_activation_layer, build_norm_layer, xavier_init
  from mmcv.cnn.bricks.drop import build_dropout
  from mmcv.cnn.bricks.registry import FEEDFORWARD_NETWORK, TRANSFORMER_LAYER, TRANSFORMER_LAYER_SEQUENCE
  from mmcv.cnn.bricks.transformer import BaseTransformerLayer, TransformerLayerSequence, build_transformer_layer_sequence
  from mmcv.runner.base_module import BaseModule, Sequential
  from mmcv.utils import deprecated_api_warning, to_2tuple
  from torch.nn.init import normal_
  from ..builder import TRANSFORMER
label_desc: Use image node_id 5 for calling the DeformableDetrTransformer obj's underlying member method code with example usage: obj.get_reference_points(spatial_shapes, valid_ratios, device) and returns: reference_points