class_docstr: DETR Transformer encoder block.
  
  Attributes:
    num_heads: Number of heads.
    qkv_dim: Dimension of the query/key/value.
    mlp_dim: Dimension of the mlp on top of attention block.
    pre_norm: If use LayerNorm before attention/mlp blocks.
    dropout_rate: Dropout rate.
    attention_dropout_rate: Dropout rate for attention weights.
    dtype: Data type of the computation (default: float32).
class_docstr_tok: ["DETR","Transformer","encoder","block",".","Attributes",":","num_heads",":","Number","of","heads",".","qkv_dim",":","Dimension","of","the","query\/key\/value",".","mlp_dim",":","Dimension","of","the","mlp","on","top","of","attention","block",".","pre_norm",":","If","use","LayerNorm","before","attention\/mlp","blocks",".","dropout_rate",":","Dropout","rate",".","attention_dropout_rate",":","Dropout","rate","for","attention","weights",".","dtype",":","Data","type","of","the","computation","(","default",":","float32",")","."]
docstr: Applies EncoderBlock module.
  
  Args:
    inputs: Input data of shape [batch_size, len, features].
    pos_embedding: Positional Embedding to be added to the queries and keys in
      the self-attention operation.
    padding_mask: Binary mask containing 0 for padding tokens.
    train: Train or not (to apply dropout).
  
  Returns:
    Output after transformer encoder block.
code: def __call__(
      self,
      inputs: jnp.ndarray,
      *,
      pos_embedding: Optional[jnp.ndarray] = None,
      padding_mask: Optional[jnp.ndarray] = None,
      train: bool = False,
  ) -> jnp.ndarray:
      """Applies EncoderBlock module.
  
      Args:
        inputs: Input data of shape [batch_size, len, features].
        pos_embedding: Positional Embedding to be added to the queries and keys in
          the self-attention operation.
        padding_mask: Binary mask containing 0 for padding tokens.
        train: Train or not (to apply dropout).
  
      Returns:
        Output after transformer encoder block.
      """
      self_attn = MultiHeadDotProductAttention(
          num_heads=self.num_heads,
          qkv_features=self.qkv_dim,
          dropout_rate=self.attention_dropout_rate,
          broadcast_dropout=False,
          kernel_init=initializers.xavier_uniform(),
          bias_init=initializers.zeros,
          use_bias=True,
          dtype=self.dtype,
      )
  
      mlp = MlpBlock(  # pytype: disable=wrong-arg-types  # jnp-type
          mlp_dim=self.mlp_dim,
          activation_fn=nn.relu,
          dtype=self.dtype,
          dropout_rate=self.dropout_rate,
      )
  
      assert inputs.ndim == 3
  
      if self.pre_norm:
          x = nn.LayerNorm(dtype=self.dtype)(inputs)
          x = self_attn(
              inputs_q=x,
              pos_emb_q=pos_embedding,
              pos_emb_k=pos_embedding,
              pos_emb_v=None,
              key_padding_mask=padding_mask,
              train=train,
          )
          x = nn.Dropout(rate=self.dropout_rate)(
              x, deterministic=not train
          )
          x = x + inputs
          y = nn.LayerNorm(dtype=self.dtype)(x)
          y = mlp(y, deterministic=not train)
          out = x + y
  
      else:
          x = self_attn(
              inputs_q=inputs,
              pos_emb_q=pos_embedding,
              pos_emb_k=pos_embedding,
              pos_emb_v=None,
              key_padding_mask=padding_mask,
              train=train,
          )
          x = nn.Dropout(rate=self.dropout_rate)(
              x, deterministic=not train
          )
          x = x + inputs
          x = nn.LayerNorm(dtype=self.dtype)(x)
          y = mlp(x, deterministic=not train)
          y = x + y
          out = nn.LayerNorm(dtype=self.dtype)(y)
  
      return out
  
imports: import functools
  from typing import Any, Callable, Dict, Tuple, Optional
  import flax.linen
  import jax
  from jax.nn import initializers
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.model_lib.layers import attention_layers
  from scenic.projects.baselines import resnet
  from scenic.projects.baselines.detr import detr_base_model
label_desc: Use image node_id 1 for calling the EncoderBlock obj's underlying member method code with example usage: obj.__call__(inputs) and returns: out