class_docstr: Transformer encoder of Deformable DETR.
docstr: Get the reference points used in encoder.
  
  Args:
      spatial_shapes (Tensor): Spatial shapes of features in all levels,
          has shape (num_levels, 2), last dimension represents (h, w).
      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).
      device (obj:`device` or str): The device acquired by the
          `reference_points`.
  
  Returns:
      Tensor: Reference points used in decoder, has shape (bs, length,
      num_levels, 2).
docstr_tok: ["Get","the","reference","points","used","in","encoder",".","Args",":","spatial_shapes","(","Tensor",")",":","Spatial","shapes","of","features","in","all","levels",",","has","shape","(","num_levels",",","2",")",",","last","dimension","represents","(","h",",","w",")",".","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",")",".","device","(","obj",":","`","device","`","or","str",")",":","The","device","acquired","by","the","`","reference_points","`",".","Returns",":","Tensor",":","Reference","points","used","in","decoder",",","has","shape","(","bs",",","length",",","num_levels",",","2",")","."]
code: def get_encoder_reference_points(
      spatial_shapes: Tensor,
      valid_ratios: Tensor,
      device: Union[torch.device, str],
  ) -> Tensor:
      """Get the reference points used in encoder.
  
      Args:
          spatial_shapes (Tensor): Spatial shapes of features in all levels,
              has shape (num_levels, 2), last dimension represents (h, w).
          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).
          device (obj:`device` or str): The device acquired by the
              `reference_points`.
  
      Returns:
          Tensor: Reference points used in decoder, has shape (bs, length,
          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)
      # [bs, sum(hw), num_level, 2]
      reference_points = (
          reference_points[:, :, None] * valid_ratios[:, None]
      )
      return reference_points
  
imports: from typing import Optional, Tuple, Union
  import torch
  from mmcv.cnn import build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN, MultiheadAttention
  from mmcv.ops import MultiScaleDeformableAttention
  from mmengine.model import ModuleList
  from torch import Tensor, nn
  from .detr_layers import DetrTransformerDecoder, DetrTransformerDecoderLayer, DetrTransformerEncoder, DetrTransformerEncoderLayer
  from .utils import inverse_sigmoid
label_desc: Use image node_id 3 for calling the DeformableDetrTransformerEncoder obj's underlying member method code with example usage: obj.get_encoder_reference_points(spatial_shapes, valid_ratios, device) and returns: reference_points