def caculate_fvd(reference_dir: str, output_dir: str, num_groups: int):
  """compute the Frechet Vedio Distance for the generated videos.

  Args:
    reference_dir: the directory for groudtruth videos.
    output_dir: the directory for a set of generated videos.
    num_groups: the number of groups
  Returns:
    the mean and variance for the FVD value over groups
  """
  # name should be sorted as we differentiate group according to the sorted name
  #

  def read_data(video_path):
    with gfile.GFile(video_path, 'rb') as f:
      video = np.load(f)['video']
    if video.dtype == np.float32:
      assert sum((video > 1e-5) & (video < 1 - 1e-5)) == 0
    return video.astype(np.float32)

  fvds = []
  feature_fn = None
  with concurrent.futures.ThreadPoolExecutor(max_workers=256) as executor:
    for i in range(num_groups):
      video_features = []
      # to avoid OOM
      limit = 25600
      logging.info('processing %d-th group in %d', i, num_groups)
      for directory in [output_dir, reference_dir]:
        video_paths = [f'{directory}/{i}/{x}'
                       for x in gfile.listdir(f'{directory}/{i}')]
        features = []
        for x in range(0, len(video_paths), limit):
          videos = []
          for v in tqdm.tqdm(
              executor.map(read_data, video_paths[x:x + limit]),
              desc='load data',
              unit='example'):
            videos.append(v)
          logging.info('finish loading %d video data for %d-th group',
                       len(videos), i)
          videos = np.stack(videos)
          if feature_fn is None:
            feature_fn = get_i3d_features(videos.shape)
          features.append(feature_fn(videos))

        video_features.append(np.concatenate(features, axis=0))
        logging.info('finish extrecting %d features for %s',
                     video_features[-1].shape[0], directory)
      fvds.append(caculate_fvd_from_activations(video_features[0],
                                                video_features[1]))
  return np.mean(fvds), np.std(fvds)
compute the Frechet Vedio Distance for the generated videos.

  Args:
    reference_dir: the directory for groudtruth videos.
    output_dir: the directory for a set of generated videos.
    num_groups: the number of groups
  Returns:
    the mean and variance for the FVD value over groups
  
videogvt/tools/compute_fvd.py