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: Get the valid radios of feature map in a level.
  
  .. code:: text
  
              |---> valid_W <---|
           ---+-----------------+-----+---
            A |                 |     | A
            | |                 |     | |
            | |                 |     | |
      valid_H |                 |     | |
            | |                 |     | H
            | |                 |     | |
            V |                 |     | |
           ---+-----------------+     | |
              |                       | V
              +-----------------------+---
              |---------> W <---------|
  
    The valid_ratios are defined as:
          r_h = valid_H / H,  r_w = valid_W / W
    They are the factors to re-normalize the relative coordinates of the
    image to the relative coordinates of the current level feature map.
  
  Args:
      mask (Tensor): Binary mask of a feature map, has shape (bs, H, W).
  
  Returns:
      Tensor: valid ratios [r_w, r_h] of a feature map, has shape (1, 2).
docstr_tok: ["Get","the","valid","radios","of","feature","map","in","a","level",".","..","code",":",":","text","|","--","-",">","valid_W","<","--","-|","--","-+","--","--","--","--","--","--","--","--","-+","--","--","-+","--","-","A","|","|","|","A","|","|","|","|","|","|","|","|","|","|","valid_H","|","|","|","|","|","|","|","|","H","|","|","|","|","|","V","|","|","|","|","--","-+","--","--","--","--","--","--","--","--","-+","|","|","|","|","V","+","--","--","--","--","--","--","--","--","--","--","--","-+","--","-","|","--","--","--","--","-",">","W","<","--","--","--","--","-|","The","valid_ratios","are","defined","as",":","r_h","=","valid_H","\/","H",",","r_w","=","valid_W","\/","W","They","are","the","factors","to","re-normalize","the","relative","coordinates","of","the","image","to","the","relative","coordinates","of","the","current","level","feature","map",".","Args",":","mask","(","Tensor",")",":","Binary","mask","of","a","feature","map",",","has","shape","(","bs",",","H",",","W",")",".","Returns",":","Tensor",":","valid","ratios","[","r_w",",","r_h","]","of","a","feature","map",",","has","shape","(","1",",","2",")","."]
code: def get_valid_ratio(mask: Tensor) -> Tensor:
      """Get the valid radios of feature map in a level.
  
      .. code:: text
  
                  |---> valid_W <---|
               ---+-----------------+-----+---
                A |                 |     | A
                | |                 |     | |
                | |                 |     | |
          valid_H |                 |     | |
                | |                 |     | H
                | |                 |     | |
                V |                 |     | |
               ---+-----------------+     | |
                  |                       | V
                  +-----------------------+---
                  |---------> W <---------|
  
        The valid_ratios are defined as:
              r_h = valid_H / H,  r_w = valid_W / W
        They are the factors to re-normalize the relative coordinates of the
        image to the relative coordinates of the current level feature map.
  
      Args:
          mask (Tensor): Binary mask of a feature map, has shape (bs, H, W).
  
      Returns:
          Tensor: valid ratios [r_w, r_h] of a feature map, has shape (1, 2).
      """
      _, H, W = mask.shape
      valid_H = torch.sum(~mask[:, :, 0], 1)
      valid_W = torch.sum(~mask[:, 0, :], 1)
      valid_ratio_h = valid_H.float() / H
      valid_ratio_w = valid_W.float() / W
      valid_ratio = torch.stack([valid_ratio_w, valid_ratio_h], -1)
      return valid_ratio
  
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 8 for calling the DeformableDETR obj's underlying member method code with example usage: obj.get_valid_ratio(mask) and returns: valid_ratio