class_docstr: Implements the PETR 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","PETR","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 valid radios of feature maps of all level.
docstr_tok: ["Get","the","valid","radios","of","feature","maps","of","all","level","."]
code: def get_valid_ratio(self, mask):
      """Get the valid radios of feature maps of all level."""
      _, H, W = mask.shape
      valid_H = paddle.sum(mask[:, :, 0].astype("float"), 1)
      valid_W = paddle.sum(mask[:, 0, :].astype("float"), 1)
      valid_ratio_h = valid_H.astype("float") / H
      valid_ratio_w = valid_W.astype("float") / W
      valid_ratio = paddle.stack([valid_ratio_w, valid_ratio_h], -1)
      return valid_ratio
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddle import ParamAttr
  from ppdet.core.workspace import register
  from ..layers import MultiHeadAttention, _convert_attention_mask
  from .utils import _get_clones
  from ..initializer import linear_init_, normal_, constant_, xavier_uniform_
label_desc: Use image node_id 6 for calling the PETRTransformer obj's underlying member method code with example usage: obj.get_valid_ratio(mask) and returns: valid_ratio