class_docstr: Sequence of DeformableDETRDecoderLayers.
  
  Attributes:
    embed_dim: Size of the hidden embedding dimension, used for query, value,
      embeddings, and outputs.
    num_heads: Number of heads. num_levels  : Number of feature levels.
    num_layers: Number of decoder layers.
    dropout: Dropout rate.
    dtype: Data type of the computation (default: float32).
docstr: Apply decoder.
  
  Args:
    query: [bs, len_q, embed_dim] of queries.
    query_pos: [bs, len_q, embed_dim] of position embedding for each query
      position.
    ref_points: [bs, len_q, box_dim] of reference points for each query.
      box_dim is in {2, 4} as ref_points can either be box cxcy or cxcywh.
    value: [bs, len_v, embed_dim] of values to be applied in cross-attention.
    pad_mask: [bs, len_v] of boolean values, where 0 indicates padding in
      value array.
    valid_ratios: [bs, num_levels, 2] of ratios of actual shape dim to padded
      dim. Range from (0, 1]; 0 is all padding (impossible) and 1 is no
      padding.
    train: Whether we are in training mode.
  
  Returns:
    [bs, len_q, embed_dim] of decoder-encoded queries and [bs, len_q, box_dim]
      of output reference points.
docstr_tok: ["Apply","decoder",".","Args",":","query",":","[","bs",",","len_q",",","embed_dim","]","of","queries",".","query_pos",":","[","bs",",","len_q",",","embed_dim","]","of","position","embedding","for","each","query","position",".","ref_points",":","[","bs",",","len_q",",","box_dim","]","of","reference","points","for","each","query",".","box_dim","is","in","{","2",",","4","}","as","ref_points","can","either","be","box","cxcy","or","cxcywh",".","value",":","[","bs",",","len_v",",","embed_dim","]","of","values","to","be","applied","in","cross-attention",".","pad_mask",":","[","bs",",","len_v","]","of","boolean","values",",","where","0","indicates","padding","in","value","array",".","valid_ratios",":","[","bs",",","num_levels",",","2","]","of","ratios","of","actual","shape","dim","to","padded","dim",".","Range","from","(","0",",","1","]",";","0","is","all","padding","(","impossible",")","and","1","is","no","padding",".","train",":","Whether","we","are","in","training","mode",".","Returns",":","[","bs",",","len_q",",","embed_dim","]","of","decoder-encoded","queries","and","[","bs",",","len_q",",","box_dim","]","of","output","reference","points","."]
code: def __call__(
      self,
      query: jnp.ndarray,
      query_pos: jnp.ndarray,
      ref_points: jnp.ndarray,
      value: jnp.ndarray,
      pad_mask: jnp.ndarray,
      valid_ratios: jnp.ndarray,
      train: bool,
  ) -> Tuple[jnp.ndarray, jnp.ndarray]:
      """Apply decoder.
  
      Args:
        query: [bs, len_q, embed_dim] of queries.
        query_pos: [bs, len_q, embed_dim] of position embedding for each query
          position.
        ref_points: [bs, len_q, box_dim] of reference points for each query.
          box_dim is in {2, 4} as ref_points can either be box cxcy or cxcywh.
        value: [bs, len_v, embed_dim] of values to be applied in cross-attention.
        pad_mask: [bs, len_v] of boolean values, where 0 indicates padding in
          value array.
        valid_ratios: [bs, num_levels, 2] of ratios of actual shape dim to padded
          dim. Range from (0, 1]; 0 is all padding (impossible) and 1 is no
          padding.
        train: Whether we are in training mode.
  
      Returns:
        [bs, len_q, embed_dim] of decoder-encoded queries and [bs, len_q, box_dim]
          of output reference points.
      """
      assert ref_points.shape[-1] in {2, 4}
  
      output = query
      output_by_layer = []
      ref_points_by_layer = []
      for i in range(self.num_layers):
          # Use valid shape ratios to keep reference points in bounds at each level.
          vratios = valid_ratios
          if ref_points.shape[-1] == 4:
              vratios = jnp.concatenate([vratios] * 2, -1)
          ref_points_input = ref_points[:, :, None] * vratios[:, None]
  
          output = DeformableDETRDecoderLayer(
              spatial_shapes=self.spatial_shapes,
              embed_dim=self.embed_dim,
              num_heads=self.num_heads,
              num_levels=self.num_levels,
              num_reference_points=self.num_reference_points,
              ffn_dim=self.ffn_dim,
              dropout=self.dropout,
              compiler_config=self.compiler_config,
              dtype=self.dtype,
              name=f"layer{i}",
          )(
              query=output,
              query_pos=query_pos,
              ref_points=ref_points_input,
              value=value,
              pad_mask=pad_mask,
              train=train,
          )
  
          bbox_offset_embed = self.bbox_embeds[i](output)
  
          if ref_points.shape[-1] == 4:
              new_ref_points = bbox_offset_embed + inverse_sigmoid(
                  ref_points
              )
          else:
              new_ref_points = bbox_offset_embed
              xy = bbox_offset_embed[..., :2] + inverse_sigmoid(
                  ref_points
              )
              # Here is where ref_points goes to 4d.
              new_ref_points = jnp.concatenate(
                  [xy, bbox_offset_embed[..., 2:]], axis=-1
              )
          ref_points = nn.sigmoid(new_ref_points)
          # To satisfy deformable detr iterative refinement must stop gradient here.
          ref_points = jax.lax.stop_gradient(ref_points)
  
          output_by_layer.append(output)
          ref_points_by_layer.append(ref_points)
  
      output, ref_points = jnp.stack(output_by_layer), jnp.stack(
          ref_points_by_layer
      )
  
      return output, ref_points
  
imports: import functools
  from typing import Sequence, Tuple
  import flax.linen
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.projects.baselines.deformable_detr.attention import MultiScaleDeformableAttention
  from scenic.projects.baselines.detr.model import MultiHeadDotProductAttention
label_desc: Use image node_id 1 for calling the DeformableDETRDecoder obj's underlying member method code with example usage: obj.__call__(query, query_pos, ref_points, value, pad_mask, valid_ratios, train) and returns: output,  ref_points