class_docstr: Embeds images and texts using the CLIP image-text model.
class_docstr_tok: ["Embeds","images","and","texts","using","the","CLIP","image-text","model","."]
docstr: Embeds images and texts using the CLIP image-text model.
docstr_tok: ["Embeds","images","and","texts","using","the","CLIP","image-text","model","."]
code: def __call__(
      self,
      *,
      images: Optional[jnp.ndarray] = None,
      texts: Optional[jnp.ndarray] = None,
      train: bool = False,
  ) -> Tuple[Optional[jnp.ndarray], Optional[jnp.ndarray]]:
      """Embeds images and texts using the CLIP image-text model."""
      texts_shape = None
      if texts is not None:
          texts_shape = texts.shape
          if len(texts_shape) > 2:
              texts = texts.reshape(-1, texts_shape[-1])
  
      model_config = clip_model.CONFIGS[self.embed_configs["variant"]]
      model_config["vision_return_map"] = True
      # Copy over additional CLIP config settings.
      for name in [
          "text_stochastic_droplayer_rate",
          "vision_stochastic_droplayer_rate",
      ]:
          if self.embed_configs.get(name) is not None:
              model_config[name] = self.embed_configs[name]
      model = clip_layers.CLIP(**model_config, name="clip")
      # Input images should have range (0.0, 1.0). Shift them to CLIP range:
      if images is not None:
          images = clip_model.normalize_image(images)
      # Don't normalize image and text embeddings.
      img_emb, txt_emb = model(
          images, texts, normalize=False, deterministic=not train
      )
      # Drop or merge class embedding token.
      if img_emb is not None:
          merge_class_token = self.embed_configs.get(
              "merge_class_token", "drop"
          )
          if merge_class_token == "drop":
              img_emb = img_emb[:, 1:, :]  # [B, P, emb_dim]
          elif merge_class_token == "mul-ln":
              class_token_out = jnp.broadcast_to(
                  img_emb[:, :1, :], np.array(img_emb.shape) - (0, 1, 0)
              )
              img_emb = (
                  img_emb[:, 1:, :] * class_token_out
              )  # [B, P, emb_dim]
              img_emb = nn.LayerNorm(name="merged_class_token")(img_emb)
          else:
              raise ValueError(
                  f"Unknown merge_class_token: {merge_class_token}"
              )
  
      if txt_emb is not None and len(texts_shape) > 2:
          txt_emb = txt_emb.reshape(texts_shape[:-1] + (-1,))
      return img_emb, txt_emb
  
imports: import abc
  import functools
  from typing import Any, Callable, Dict, Optional, Tuple, Union, Sequence
  from absl import logging
  from big_vision.models import bit
  from big_vision.models import vit
  import flax
  import flax.linen
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.model_lib.base_models import box_utils
  from scenic.projects.owl_vit import utils
  from scenic.projects.owl_vit.clip import layers
  from scenic.projects.owl_vit.clip import model
label_desc: Use image node_id 1 for calling the ClipImageTextEmbedder obj's underlying member method code with example usage: obj.__call__() and returns: img_emb,  txt_emb