class_docstr: Tests for DeformableDETRTransformer and utilities.
class_docstr_tok: ["Tests","for","DeformableDETRTransformer","and","utilities","."]
docstr: Test get_mask_valid_ratio.
docstr_tok: ["Test","get_mask_valid_ratio","."]
code: def test_get_mask_valid_ratio(self):
      """Test get_mask_valid_ratio."""
      shapes = ((10, 15), (6, 2), (30, 30))
      # Make masks of each shape, where only first pixel is not-padding.
      max_d = 30
  
      def create_mask(h, w):
          pad = ((0, max_d - h), (0, max_d - w))
          m = np.ones((h, w), dtype=bool)
          return np.pad(m, pad, "constant", constant_values=False)
  
      masks = np.stack([create_mask(h, w) for w, h in shapes], 0)
  
      out = get_mask_valid_ratio(masks)
      exp_ratios = np.array(shapes, dtype=float) / max_d
      self.assertSequenceAlmostEqual(
          exp_ratios.flatten(), out.flatten()
      )
  
imports: from absl.testing import absltest
  from absl.testing import parameterized
  import flax.linen
  import jax
  from jax import random
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.projects.baselines.deformable_detr.deformable_transformer import BBoxCoordPredictor
  from scenic.projects.baselines.deformable_detr.deformable_transformer import DeformableDETRDecoder
  from scenic.projects.baselines.deformable_detr.deformable_transformer import DeformableDETRDecoderLayer
  from scenic.projects.baselines.deformable_detr.deformable_transformer import DeformableDETREncoder
  from scenic.projects.baselines.deformable_detr.deformable_transformer import DeformableDETREncoderLayer
  from scenic.projects.baselines.deformable_detr.deformable_transformer import DeformableDETRTransformer
  from scenic.projects.baselines.deformable_detr.deformable_transformer import get_encoder_reference_points
  from scenic.projects.baselines.deformable_detr.deformable_transformer import get_mask_valid_ratio
  from scenic.projects.baselines.deformable_detr.deformable_transformer import inverse_sigmoid
label_desc: Use image node_id 1 for calling the DeformableDETRTransformerTest obj's underlying member method code with example usage: obj.test_get_mask_valid_ratio() and returns: np