code: def sample_sequence_uniformly(
      sequence: tf.Tensor, num_steps: int, is_training: bool = True
  ) -> tf.Tensor:
      """Uniform frame sampling.
  
      Sample frames based on uniform sampling following TSN (Wang et al., 2019)
      used by Tong et al. in VideoMAE. The stride is automatically computed based on
      the length of the sequence and the number of frames to take (`num_steps`). If
      `is_training` is set to False, a deterministic sequence will be returned.
  
      Args:
        sequence: Any tensor where the first dimension is timesteps.
        num_steps: Number of steps (e.g. frames) to take.
        is_training: If is called during training or not.
      Returns:
         A single tensor with first dimension `num_steps` with the sampled segment.
      """
  
      sequence_length = tf.shape(input=sequence)[0]
      sequence_length = tf.cast(sequence_length, tf.int32)
      stride = tf.cast(sequence_length // num_steps, tf.int32)
  
      if stride > 0:
          indices = tf.math.multiply(tf.range(num_steps), stride)
          if is_training:
              indices = indices + tf.random.uniform(
                  shape=(1, num_steps),
                  minval=0,
                  maxval=stride,
                  dtype=tf.int32,
              )
      else:
          if is_training:
              indices = tf.sort(
                  tf.random.uniform(
                      shape=(1, num_steps),
                      minval=0,
                      maxval=sequence_length,
                      dtype=tf.int32,
                  )
              )
          else:
              stride_float = tf.cast(
                  sequence_length / num_steps, tf.float32
              )
              indices = tf.cast(
                  tf.range(num_steps, dtype=tf.float32) * stride_float,
                  tf.int32,
              )
      if is_training:
          indices = indices[0]
  
      indices.set_shape((num_steps,))
      output = tf.gather(sequence, indices)
      return output
  
imports: from typing import Optional, Union
  from absl import logging
  from dmvr import builders
  from dmvr import processors
  import ml_collections
  import tensorflow
label_desc: Use image node_id 15 for calling a global function with example usage: sample_sequence_uniformly(sequence, num_steps, is_training) and returns: output