def pool_overlapping_segments(x: np.ndarray,
                              overlapping_frames: int = 4,
                              alphas: Optional[Any] = None):
  """weighted pools the output pixels or the intermediate embeddings.

  Args:
    x: video pixels or embeddings in [#segments t h w c].
    overlapping_frames: overlapping frames to pool.
    alphas: A scalar of a 1d array of len overlapping_frames.

  Returns:
    Features pooled by overlapping segments.
  """
  assert x.ndim == 5, 'x should be in shape [bs t h w c]'
  _, t = x.shape[0], x.shape[1]
  assert overlapping_frames > 0, f'Bad overlapping_frames={overlapping_frames}'
  assert overlapping_frames <= t // 2, 'Case not supported yet.'
  if alphas is None:  # linear interpolation
    alphas = np.arange(0., 1., step=1./overlapping_frames)
    alphas = alphas[:, None, None, None]

  step_size = t-overlapping_frames

  ret = []
  first_segment = x[0, 0: (t-overlapping_frames), ...]
  last_segment = x[-1, -overlapping_frames:]
  for i in range(1, x.shape[0]):
    cur_segment = (1 - alphas) * x[i - 1, -overlapping_frames:] + alphas * x[
        i, 0:overlapping_frames]
    ret.append(cur_segment)
    if step_size > overlapping_frames:
      ret.append(x[i, overlapping_frames:step_size])
  ret = np.concatenate(ret)
  ret = np.reshape(ret, [-1, *x.shape[2:]])
  ret = np.concatenate((first_segment, ret, last_segment))
  num_pad_frames = int(np.ceil(ret.shape[0] / t)*t-ret.shape[0])
  if num_pad_frames > 0:
    ret = np.concatenate((ret, np.zeros([num_pad_frames, *x.shape[2:]])))
  ret = np.reshape(ret, [-1, *x.shape[1:]])
  return ret
weighted pools the output pixels or the intermediate embeddings.

  Args:
    x: video pixels or embeddings in [#segments t h w c].
    overlapping_frames: overlapping frames to pool.
    alphas: A scalar of a 1d array of len overlapping_frames.

  Returns:
    Features pooled by overlapping segments.
  
videogvt/train_lib/train_utils.py