class_docstr: Use a clip image encoder to encode video frames as in CLIP4CLIP.
  
  Attributes:
    config: The config to create the image model from.
    temporal_agg: How to agregate embeddings of the different frames.
class_docstr_tok: ["Use","a","clip","image","encoder","to","encode","video","frames","as","in","CLIP4CLIP",".","Attributes",":","config",":","The","config","to","create","the","image","model","from",".","temporal_agg",":","How","to","agregate","embeddings","of","the","different","frames","."]
code: def __call__(self, x, *, train: bool, debug: bool = False):
      # Reshape and normalise video frames
      all_frames = x.reshape((-1,) + x.shape[-3:])
      all_frames = clip.normalize_image(all_frames)
      image_encoder = clip_layers.VisionTransformer(
          name="ImageTower", **self.config
      )
      video_embeddings, _ = image_encoder(x=all_frames)
      video_embeddings = video_embeddings.reshape(x.shape[:-3] + (-1,))
  
      # Mean pooling across frame features.
      if self.temporal_agg == "meanpool":
          video_embeddings = jnp.mean(video_embeddings, axis=1)
  
      # Temporal aggregation with a transformer across frame features.
      elif self.temporal_agg == "transformer":
          feature_dim = video_embeddings.shape[-1]
          positional_embedding = self.param(
              "seqTrans_positional_embedding",
              jax.nn.initializers.zeros,
              (video_embeddings.shape[1], feature_dim),
          )
          frame_embs = video_embeddings + positional_embedding[None]
          frame_embs = clip.layers.Transformer(
              feature_dim,
              self.transformer_aggregation_num_layer,
              feature_dim // 64,
              name="seqTrans_transformer",
          )(frame_embs)
          video_embeddings += frame_embs  # residual
          # seqTrans Clip4clip l2-normalizes *before* and after mean pooling.
          video_embeddings /= (
              jnp.linalg.norm(video_embeddings, axis=-1, keepdims=True)
              + 1e-8
          )
          video_embeddings = jnp.mean(video_embeddings, axis=1)
      return video_embeddings
  
imports: from typing import Any, Optional
  import flax.linen
  import jax
  import jax.numpy
  import ml_collections
  from scenic.model_lib.base_models import base_model
  from scenic.projects.baselines.clip import layers
  from scenic.projects.baselines.clip import model
  from scenic.projects.verbs_in_action import losses
  from scenic.projects.verbs_in_action import utils
label_desc: Use image node_id 1 for calling the Image2VideoEncoder obj's underlying member method code with example usage: obj.__call__(x) and returns: video_embeddings