class_docstr: Transform a batch of views into a sequence of tokens.
code: def __call__(
      self,
      x: jnp.ndarray,
      positional_embedding: str = "",
      seqlen: int = -1,
      seqlen_selection: str = "unstructured",
  ):
      # Extracting patches and then embedding is in fact a single convolution.
      fh, fw = self.patches.size
      x = nn.Conv(
          self.hidden_size,
          (fh, fw),
          strides=(fh, fw),
          padding="VALID",
          name="embedding",
      )(x)
  
      # Adding positional encodings.
      x = self.add_positional_encodings(x, positional_embedding)
  
      # Possibly dropping some tokens.
      idx_kept_tokens = None
      n_tokens = self.posembs[0] * self.posembs[1]
      if seqlen > 0:
          rng = self.make_rng("droptok")
          idx_kept_tokens = token_indexes_not_to_drop(
              seqlen, n_tokens, seqlen_selection, rng
          )
          if len(idx_kept_tokens) < n_tokens:
              x = jnp.take(x, idx_kept_tokens, axis=1)
  
      return x, idx_kept_tokens
  
imports: import copy
  import functools
  from typing import Any, Optional, Tuple
  import flax.linen
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.model_lib.base_models import base_model
  from scenic.model_lib.base_models import classification_model
  from scenic.model_lib.base_models import model_utils
  from scenic.model_lib.layers import attention_layers
  from scenic.model_lib.layers import nn_layers
  from scenic.projects.baselines import vit
label_desc: Use image node_id 2 for calling the ToTokenSequence obj's underlying member method code with example usage: obj.__call__(x, positional_embedding, seqlen, seqlen_selection) and returns: x,  idx_kept_tokens