加载视频数据

在 TensorFlow.org 上查看 在 Google Colab 中运行 在 GitHub 上查看源代码 下载笔记本

本教程演示如何使用 UCF101 人体动作数据集加载和预处理 AVI 视频数据。当您对数据进行预处理后,就可以将其用于视频分类/识别、字幕或聚类等任务。原始数据集包含从 YouTube 收集的具有 101 个类别的真实动作视频,包括演奏大提琴、刷牙和化眼妆。您将学习如何:

  • 从 ZIP 文件加载数据。

  • 从视频文件中读取帧序列。

  • 呈现视频数据。

  • 封装帧生成器 tf.data.Dataset

本视频加载和预处理教程是 TensorFlow 视频教程系列的第一部分。下面是其他三个教程:

安装

首先,安装和导入一些必要的库,包括:用于检查 ZIP 文件内容的 remotezip,用于使用进度条的 tqdm,用于处理视频文件的 OpenCV,以及用于在 Jupyter 笔记本中嵌入数据的 tensorflow_docs

# The way this tutorial uses the `TimeDistributed` layer requires TF>=2.10
pip install -U "tensorflow>=2.10.0"
pip install remotezip tqdm opencv-python
pip install -q git+https://github.com/tensorflow/docs
import tqdm
import random
import pathlib
import itertools
import collections

import os
import cv2
import numpy as np
import remotezip as rz

import tensorflow as tf

# Some modules to display an animation using imageio.
import imageio
from IPython import display
from urllib import request
from tensorflow_docs.vis import embed
2023-11-07 23:37:06.494330: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2023-11-07 23:37:06.494378: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2023-11-07 23:37:06.496111: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered

下载 UCF101 数据集的子集

UCF101 数据集包含 101 类不同动作的视频,主要用于动作识别。您将在此演示中使用这些类别的一个子集。

URL = 'https://storage.googleapis.com/thumos14_files/UCF101_videos.zip'

上面的网址包含一个带有 UCF 101 数据集的 ZIP 文件。创建一个使用 remotezip 库的函数来检查该 URL 中 ZIP 文件的内容:

def list_files_from_zip_url(zip_url):
  """ List the files in each class of the dataset given a URL with the zip file.

    Args:
      zip_url: A URL from which the files can be extracted from.

    Returns:
      List of files in each of the classes.
  """
  files = []
  with rz.RemoteZip(zip_url) as zip:
    for zip_info in zip.infolist():
      files.append(zip_info.filename)
  return files
files = list_files_from_zip_url(URL)
files = [f for f in files if f.endswith('.avi')]
files[:10]
['UCF101/v_ApplyEyeMakeup_g01_c01.avi',
 'UCF101/v_ApplyEyeMakeup_g01_c02.avi',
 'UCF101/v_ApplyEyeMakeup_g01_c03.avi',
 'UCF101/v_ApplyEyeMakeup_g01_c04.avi',
 'UCF101/v_ApplyEyeMakeup_g01_c05.avi',
 'UCF101/v_ApplyEyeMakeup_g01_c06.avi',
 'UCF101/v_ApplyEyeMakeup_g02_c01.avi',
 'UCF101/v_ApplyEyeMakeup_g02_c02.avi',
 'UCF101/v_ApplyEyeMakeup_g02_c03.avi',
 'UCF101/v_ApplyEyeMakeup_g02_c04.avi']

先从几个视频和有限数量的类开始训练。运行上述代码块后,请注意类名包含在每个视频的文件名中。

定义从文件名中检索类名的 get_class 函数。然后,创建一个名为 get_files_per_class 的函数,它会将所有文件的列表(上面的 files)转换为列出每个类的文件的字典:

def get_class(fname):
  """ Retrieve the name of the class given a filename.

    Args:
      fname: Name of the file in the UCF101 dataset.

    Returns:
      Class that the file belongs to.
  """
  return fname.split('_')[-3]
def get_files_per_class(files):
  """ Retrieve the files that belong to each class.

    Args:
      files: List of files in the dataset.

    Returns:
      Dictionary of class names (key) and files (values). 
  """
  files_for_class = collections.defaultdict(list)
  for fname in files:
    class_name = get_class(fname)
    files_for_class[class_name].append(fname)
  return files_for_class

获得每个类的文件列表后,您可以选择要使用多少个类,以及每个类需要多少视频,以创建数据集。

NUM_CLASSES = 10
FILES_PER_CLASS = 50
files_for_class = get_files_per_class(files)
classes = list(files_for_class.keys())
print('Num classes:', len(classes))
print('Num videos for class[0]:', len(files_for_class[classes[0]]))
Num classes: 101
Num videos for class[0]: 145

创建一个名为 select_subset_of_classes 的新函数,它会选择数据集中存在的类的子集并在每个类中选择特定数量的文件:

def select_subset_of_classes(files_for_class, classes, files_per_class):
  """ Create a dictionary with the class name and a subset of the files in that class.

    Args:
      files_for_class: Dictionary of class names (key) and files (values).
      classes: List of classes.
      files_per_class: Number of files per class of interest.

    Returns:
      Dictionary with class as key and list of specified number of video files in that class.
  """
  files_subset = dict()

  for class_name in classes:
    class_files = files_for_class[class_name]
    files_subset[class_name] = class_files[:files_per_class]

  return files_subset
files_subset = select_subset_of_classes(files_for_class, classes[:NUM_CLASSES], FILES_PER_CLASS)
list(files_subset.keys())
['ApplyEyeMakeup',
 'ApplyLipstick',
 'Archery',
 'BabyCrawling',
 'BalanceBeam',
 'BandMarching',
 'BaseballPitch',
 'BasketballDunk',
 'Basketball',
 'BenchPress']

定义将视频拆分为训练集、验证集和测试集的辅助函数。视频从带有 ZIP 文件的网址下载,并放置在各自的子目录中。

def download_from_zip(zip_url, to_dir, file_names):
  """ Download the contents of the zip file from the zip URL.

    Args:
      zip_url: A URL with a zip file containing data.
      to_dir: A directory to download data to.
      file_names: Names of files to download.
  """
  with rz.RemoteZip(zip_url) as zip:
    for fn in tqdm.tqdm(file_names):
      class_name = get_class(fn)
      zip.extract(fn, str(to_dir / class_name))
      unzipped_file = to_dir / class_name / fn

      fn = pathlib.Path(fn).parts[-1]
      output_file = to_dir / class_name / fn
      unzipped_file.rename(output_file)

以下函数会返回尚未放入数据子集的剩余数据。它允许您将剩余的数据放在下一个指定的数据子集中。

def split_class_lists(files_for_class, count):
  """ Returns the list of files belonging to a subset of data as well as the remainder of
    files that need to be downloaded.

    Args:
      files_for_class: Files belonging to a particular class of data.
      count: Number of files to download.

    Returns:
      Files belonging to the subset of data and dictionary of the remainder of files that need to be downloaded.
  """
  split_files = []
  remainder = {}
  for cls in files_for_class:
    split_files.extend(files_for_class[cls][:count])
    remainder[cls] = files_for_class[cls][count:]
  return split_files, remainder

下面的 download_ufc_101_subset 函数允许您下载 UCF101 数据集的子集并将其拆分为训练集、验证集和测试集。您可以指定要使用的类的数量。splits 参数允许您传入一个字典,其中键值是子集的名称(例如:“train”)和您希望每个类拥有的视频数量。

def download_ucf_101_subset(zip_url, num_classes, splits, download_dir):
  """ Download a subset of the UCF101 dataset and split them into various parts, such as
    training, validation, and test.

    Args:
      zip_url: A URL with a ZIP file with the data.
      num_classes: Number of labels.
      splits: Dictionary specifying the training, validation, test, etc. (key) division of data 
              (value is number of files per split).
      download_dir: Directory to download data to.

    Return:
      Mapping of the directories containing the subsections of data.
  """
  files = list_files_from_zip_url(zip_url)
  for f in files:
    path = os.path.normpath(f)
    tokens = path.split(os.sep)
    if len(tokens) <= 2:
      files.remove(f) # Remove that item from the list if it does not have a filename

  files_for_class = get_files_per_class(files)

  classes = list(files_for_class.keys())[:num_classes]

  for cls in classes:
    random.shuffle(files_for_class[cls])

  # Only use the number of classes you want in the dictionary
  files_for_class = {x: files_for_class[x] for x in classes}

  dirs = {}
  for split_name, split_count in splits.items():
    print(split_name, ":")
    split_dir = download_dir / split_name
    split_files, files_for_class = split_class_lists(files_for_class, split_count)
    download_from_zip(zip_url, split_dir, split_files)
    dirs[split_name] = split_dir

  return dirs
download_dir = pathlib.Path('./UCF101_subset/')
subset_paths = download_ucf_101_subset(URL,
                                       num_classes = NUM_CLASSES,
                                       splits = {"train": 30, "val": 10, "test": 10},
                                       download_dir = download_dir)
train :
100%|██████████| 300/300 [00:34<00:00,  8.63it/s]
val :
100%|██████████| 100/100 [00:12<00:00,  7.82it/s]
test :
100%|██████████| 100/100 [00:12<00:00,  8.24it/s]

下载数据后,您现在应该拥有了一个 UCF101 数据集子集的副本。运行以下代码即可打印您在所有数据子集中拥有的视频总数。

video_count_train = len(list(download_dir.glob('train/*/*.avi')))
video_count_val = len(list(download_dir.glob('val/*/*.avi')))
video_count_test = len(list(download_dir.glob('test/*/*.avi')))
video_total = video_count_train + video_count_val + video_count_test
print(f"Total videos: {video_total}")
Total videos: 500

您现在还可以预览数据文件的目录。

find ./UCF101_subset
./UCF101_subset
./UCF101_subset/val
./UCF101_subset/val/BenchPress
./UCF101_subset/val/BenchPress/v_BenchPress_g06_c05.avi
./UCF101_subset/val/BenchPress/v_BenchPress_g11_c01.avi
./UCF101_subset/val/BenchPress/v_BenchPress_g06_c01.avi
./UCF101_subset/val/BenchPress/v_BenchPress_g02_c07.avi
./UCF101_subset/val/BenchPress/UCF101
./UCF101_subset/val/BenchPress/v_BenchPress_g08_c01.avi
./UCF101_subset/val/BenchPress/v_BenchPress_g14_c04.avi
./UCF101_subset/val/BenchPress/v_BenchPress_g07_c04.avi
./UCF101_subset/val/BenchPress/v_BenchPress_g08_c07.avi
./UCF101_subset/val/BenchPress/v_BenchPress_g03_c06.avi
./UCF101_subset/val/BenchPress/v_BenchPress_g24_c05.avi
./UCF101_subset/val/BabyCrawling
./UCF101_subset/val/BabyCrawling/v_BabyCrawling_g16_c05.avi
./UCF101_subset/val/BabyCrawling/v_BabyCrawling_g15_c01.avi
./UCF101_subset/val/BabyCrawling/v_BabyCrawling_g19_c04.avi
./UCF101_subset/val/BabyCrawling/v_BabyCrawling_g13_c05.avi
./UCF101_subset/val/BabyCrawling/v_BabyCrawling_g10_c04.avi
./UCF101_subset/val/BabyCrawling/v_BabyCrawling_g05_c01.avi
./UCF101_subset/val/BabyCrawling/v_BabyCrawling_g24_c03.avi
./UCF101_subset/val/BabyCrawling/v_BabyCrawling_g15_c05.avi
./UCF101_subset/val/BabyCrawling/UCF101
./UCF101_subset/val/BabyCrawling/v_BabyCrawling_g14_c01.avi
./UCF101_subset/val/BabyCrawling/v_BabyCrawling_g02_c03.avi
./UCF101_subset/val/BasketballDunk
./UCF101_subset/val/BasketballDunk/v_BasketballDunk_g16_c06.avi
./UCF101_subset/val/BasketballDunk/v_BasketballDunk_g14_c02.avi
./UCF101_subset/val/BasketballDunk/v_BasketballDunk_g07_c01.avi
./UCF101_subset/val/BasketballDunk/UCF101
./UCF101_subset/val/BasketballDunk/v_BasketballDunk_g19_c03.avi
./UCF101_subset/val/BasketballDunk/v_BasketballDunk_g17_c06.avi
./UCF101_subset/val/BasketballDunk/v_BasketballDunk_g13_c04.avi
./UCF101_subset/val/BasketballDunk/v_BasketballDunk_g01_c06.avi
./UCF101_subset/val/BasketballDunk/v_BasketballDunk_g13_c02.avi
./UCF101_subset/val/BasketballDunk/v_BasketballDunk_g03_c01.avi
./UCF101_subset/val/BasketballDunk/v_BasketballDunk_g08_c01.avi
./UCF101_subset/val/ApplyEyeMakeup
./UCF101_subset/val/ApplyEyeMakeup/v_ApplyEyeMakeup_g21_c04.avi
./UCF101_subset/val/ApplyEyeMakeup/v_ApplyEyeMakeup_g15_c02.avi
./UCF101_subset/val/ApplyEyeMakeup/v_ApplyEyeMakeup_g22_c03.avi
./UCF101_subset/val/ApplyEyeMakeup/v_ApplyEyeMakeup_g25_c07.avi
./UCF101_subset/val/ApplyEyeMakeup/v_ApplyEyeMakeup_g03_c01.avi
./UCF101_subset/val/ApplyEyeMakeup/v_ApplyEyeMakeup_g23_c06.avi
./UCF101_subset/val/ApplyEyeMakeup/UCF101
./UCF101_subset/val/ApplyEyeMakeup/v_ApplyEyeMakeup_g04_c01.avi
./UCF101_subset/val/ApplyEyeMakeup/v_ApplyEyeMakeup_g03_c03.avi
./UCF101_subset/val/ApplyEyeMakeup/v_ApplyEyeMakeup_g20_c06.avi
./UCF101_subset/val/ApplyEyeMakeup/v_ApplyEyeMakeup_g13_c05.avi
./UCF101_subset/val/Basketball
./UCF101_subset/val/Basketball/v_Basketball_g21_c01.avi
./UCF101_subset/val/Basketball/v_Basketball_g15_c03.avi
./UCF101_subset/val/Basketball/v_Basketball_g16_c02.avi
./UCF101_subset/val/Basketball/v_Basketball_g13_c02.avi
./UCF101_subset/val/Basketball/v_Basketball_g18_c04.avi
./UCF101_subset/val/Basketball/UCF101
./UCF101_subset/val/Basketball/v_Basketball_g09_c02.avi
./UCF101_subset/val/Basketball/v_Basketball_g24_c02.avi
./UCF101_subset/val/Basketball/v_Basketball_g19_c05.avi
./UCF101_subset/val/Basketball/v_Basketball_g25_c04.avi
./UCF101_subset/val/Basketball/v_Basketball_g08_c02.avi
./UCF101_subset/val/ApplyLipstick
./UCF101_subset/val/ApplyLipstick/v_ApplyLipstick_g22_c02.avi
./UCF101_subset/val/ApplyLipstick/v_ApplyLipstick_g21_c01.avi
./UCF101_subset/val/ApplyLipstick/v_ApplyLipstick_g01_c02.avi
./UCF101_subset/val/ApplyLipstick/v_ApplyLipstick_g07_c02.avi
./UCF101_subset/val/ApplyLipstick/v_ApplyLipstick_g02_c03.avi
./UCF101_subset/val/ApplyLipstick/v_ApplyLipstick_g05_c02.avi
./UCF101_subset/val/ApplyLipstick/UCF101
./UCF101_subset/val/ApplyLipstick/v_ApplyLipstick_g22_c06.avi
./UCF101_subset/val/ApplyLipstick/v_ApplyLipstick_g18_c02.avi
./UCF101_subset/val/ApplyLipstick/v_ApplyLipstick_g23_c03.avi
./UCF101_subset/val/ApplyLipstick/v_ApplyLipstick_g19_c02.avi
./UCF101_subset/val/BalanceBeam
./UCF101_subset/val/BalanceBeam/v_BalanceBeam_g02_c01.avi
./UCF101_subset/val/BalanceBeam/v_BalanceBeam_g09_c04.avi
./UCF101_subset/val/BalanceBeam/v_BalanceBeam_g15_c03.avi
./UCF101_subset/val/BalanceBeam/v_BalanceBeam_g01_c01.avi
./UCF101_subset/val/BalanceBeam/v_BalanceBeam_g24_c03.avi
./UCF101_subset/val/BalanceBeam/UCF101
./UCF101_subset/val/BalanceBeam/v_BalanceBeam_g16_c03.avi
./UCF101_subset/val/BalanceBeam/v_BalanceBeam_g19_c03.avi
./UCF101_subset/val/BalanceBeam/v_BalanceBeam_g06_c01.avi
./UCF101_subset/val/BalanceBeam/v_BalanceBeam_g11_c04.avi
./UCF101_subset/val/BalanceBeam/v_BalanceBeam_g06_c05.avi
./UCF101_subset/val/BaseballPitch
./UCF101_subset/val/BaseballPitch/v_BaseballPitch_g23_c05.avi
./UCF101_subset/val/BaseballPitch/v_BaseballPitch_g02_c04.avi
./UCF101_subset/val/BaseballPitch/v_BaseballPitch_g03_c06.avi
./UCF101_subset/val/BaseballPitch/v_BaseballPitch_g06_c03.avi
./UCF101_subset/val/BaseballPitch/v_BaseballPitch_g07_c04.avi
./UCF101_subset/val/BaseballPitch/UCF101
./UCF101_subset/val/BaseballPitch/v_BaseballPitch_g13_c01.avi
./UCF101_subset/val/BaseballPitch/v_BaseballPitch_g17_c03.avi
./UCF101_subset/val/BaseballPitch/v_BaseballPitch_g07_c06.avi
./UCF101_subset/val/BaseballPitch/v_BaseballPitch_g15_c06.avi
./UCF101_subset/val/BaseballPitch/v_BaseballPitch_g06_c05.avi
./UCF101_subset/val/BandMarching
./UCF101_subset/val/BandMarching/v_BandMarching_g12_c04.avi
./UCF101_subset/val/BandMarching/v_BandMarching_g12_c06.avi
./UCF101_subset/val/BandMarching/v_BandMarching_g19_c01.avi
./UCF101_subset/val/BandMarching/v_BandMarching_g22_c04.avi
./UCF101_subset/val/BandMarching/v_BandMarching_g14_c03.avi
./UCF101_subset/val/BandMarching/v_BandMarching_g11_c05.avi
./UCF101_subset/val/BandMarching/v_BandMarching_g10_c02.avi
./UCF101_subset/val/BandMarching/v_BandMarching_g18_c05.avi
./UCF101_subset/val/BandMarching/UCF101
./UCF101_subset/val/BandMarching/v_BandMarching_g15_c01.avi
./UCF101_subset/val/BandMarching/v_BandMarching_g09_c07.avi
./UCF101_subset/val/Archery
./UCF101_subset/val/Archery/v_Archery_g02_c07.avi
./UCF101_subset/val/Archery/v_Archery_g15_c06.avi
./UCF101_subset/val/Archery/v_Archery_g17_c02.avi
./UCF101_subset/val/Archery/v_Archery_g04_c03.avi
./UCF101_subset/val/Archery/v_Archery_g06_c03.avi
./UCF101_subset/val/Archery/v_Archery_g09_c06.avi
./UCF101_subset/val/Archery/v_Archery_g11_c04.avi
./UCF101_subset/val/Archery/v_Archery_g22_c02.avi
./UCF101_subset/val/Archery/UCF101
./UCF101_subset/val/Archery/v_Archery_g25_c02.avi
./UCF101_subset/val/Archery/v_Archery_g13_c01.avi
./UCF101_subset/test
./UCF101_subset/test/BenchPress
./UCF101_subset/test/BenchPress/v_BenchPress_g13_c03.avi
./UCF101_subset/test/BenchPress/v_BenchPress_g17_c04.avi
./UCF101_subset/test/BenchPress/v_BenchPress_g04_c01.avi
./UCF101_subset/test/BenchPress/v_BenchPress_g19_c02.avi
./UCF101_subset/test/BenchPress/v_BenchPress_g15_c01.avi
./UCF101_subset/test/BenchPress/UCF101
./UCF101_subset/test/BenchPress/v_BenchPress_g15_c03.avi
./UCF101_subset/test/BenchPress/v_BenchPress_g06_c07.avi
./UCF101_subset/test/BenchPress/v_BenchPress_g06_c03.avi
./UCF101_subset/test/BenchPress/v_BenchPress_g22_c01.avi
./UCF101_subset/test/BenchPress/v_BenchPress_g19_c06.avi
./UCF101_subset/test/BabyCrawling
./UCF101_subset/test/BabyCrawling/v_BabyCrawling_g14_c03.avi
./UCF101_subset/test/BabyCrawling/v_BabyCrawling_g24_c01.avi
./UCF101_subset/test/BabyCrawling/v_BabyCrawling_g08_c04.avi
./UCF101_subset/test/BabyCrawling/v_BabyCrawling_g18_c06.avi
./UCF101_subset/test/BabyCrawling/v_BabyCrawling_g20_c05.avi
./UCF101_subset/test/BabyCrawling/v_BabyCrawling_g01_c03.avi
./UCF101_subset/test/BabyCrawling/UCF101
./UCF101_subset/test/BabyCrawling/v_BabyCrawling_g25_c05.avi
./UCF101_subset/test/BabyCrawling/v_BabyCrawling_g17_c05.avi
./UCF101_subset/test/BabyCrawling/v_BabyCrawling_g06_c02.avi
./UCF101_subset/test/BabyCrawling/v_BabyCrawling_g23_c01.avi
./UCF101_subset/test/BasketballDunk
./UCF101_subset/test/BasketballDunk/v_BasketballDunk_g06_c03.avi
./UCF101_subset/test/BasketballDunk/v_BasketballDunk_g22_c01.avi
./UCF101_subset/test/BasketballDunk/v_BasketballDunk_g10_c03.avi
./UCF101_subset/test/BasketballDunk/v_BasketballDunk_g04_c01.avi
./UCF101_subset/test/BasketballDunk/v_BasketballDunk_g05_c03.avi
./UCF101_subset/test/BasketballDunk/v_BasketballDunk_g07_c03.avi
./UCF101_subset/test/BasketballDunk/v_BasketballDunk_g07_c05.avi
./UCF101_subset/test/BasketballDunk/UCF101
./UCF101_subset/test/BasketballDunk/v_BasketballDunk_g18_c03.avi
./UCF101_subset/test/BasketballDunk/v_BasketballDunk_g23_c01.avi
./UCF101_subset/test/BasketballDunk/v_BasketballDunk_g24_c02.avi
./UCF101_subset/test/ApplyEyeMakeup
./UCF101_subset/test/ApplyEyeMakeup/v_ApplyEyeMakeup_g05_c02.avi
./UCF101_subset/test/ApplyEyeMakeup/v_ApplyEyeMakeup_g11_c02.avi
./UCF101_subset/test/ApplyEyeMakeup/v_ApplyEyeMakeup_g12_c01.avi
./UCF101_subset/test/ApplyEyeMakeup/v_ApplyEyeMakeup_g15_c04.avi
./UCF101_subset/test/ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c05.avi
./UCF101_subset/test/ApplyEyeMakeup/v_ApplyEyeMakeup_g15_c06.avi
./UCF101_subset/test/ApplyEyeMakeup/UCF101
./UCF101_subset/test/ApplyEyeMakeup/v_ApplyEyeMakeup_g09_c04.avi
./UCF101_subset/test/ApplyEyeMakeup/v_ApplyEyeMakeup_g24_c04.avi
./UCF101_subset/test/ApplyEyeMakeup/v_ApplyEyeMakeup_g17_c04.avi
./UCF101_subset/test/ApplyEyeMakeup/v_ApplyEyeMakeup_g16_c01.avi
./UCF101_subset/test/Basketball
./UCF101_subset/test/Basketball/v_Basketball_g25_c06.avi
./UCF101_subset/test/Basketball/v_Basketball_g09_c04.avi
./UCF101_subset/test/Basketball/v_Basketball_g06_c04.avi
./UCF101_subset/test/Basketball/v_Basketball_g19_c01.avi
./UCF101_subset/test/Basketball/v_Basketball_g05_c04.avi
./UCF101_subset/test/Basketball/UCF101
./UCF101_subset/test/Basketball/v_Basketball_g01_c05.avi
./UCF101_subset/test/Basketball/v_Basketball_g01_c01.avi
./UCF101_subset/test/Basketball/v_Basketball_g04_c02.avi
./UCF101_subset/test/Basketball/v_Basketball_g18_c02.avi
./UCF101_subset/test/Basketball/v_Basketball_g23_c06.avi
./UCF101_subset/test/ApplyLipstick
./UCF101_subset/test/ApplyLipstick/v_ApplyLipstick_g21_c05.avi
./UCF101_subset/test/ApplyLipstick/v_ApplyLipstick_g12_c04.avi
./UCF101_subset/test/ApplyLipstick/UCF101
./UCF101_subset/test/ApplyLipstick/v_ApplyLipstick_g15_c01.avi
./UCF101_subset/test/ApplyLipstick/v_ApplyLipstick_g08_c02.avi
./UCF101_subset/test/ApplyLipstick/v_ApplyLipstick_g07_c04.avi
./UCF101_subset/test/ApplyLipstick/v_ApplyLipstick_g01_c04.avi
./UCF101_subset/test/ApplyLipstick/v_ApplyLipstick_g06_c01.avi
./UCF101_subset/test/ApplyLipstick/v_ApplyLipstick_g25_c04.avi
./UCF101_subset/test/ApplyLipstick/v_ApplyLipstick_g11_c04.avi
./UCF101_subset/test/ApplyLipstick/v_ApplyLipstick_g09_c04.avi
./UCF101_subset/test/BalanceBeam
./UCF101_subset/test/BalanceBeam/v_BalanceBeam_g18_c03.avi
./UCF101_subset/test/BalanceBeam/v_BalanceBeam_g21_c05.avi
./UCF101_subset/test/BalanceBeam/v_BalanceBeam_g23_c04.avi
./UCF101_subset/test/BalanceBeam/v_BalanceBeam_g07_c02.avi
./UCF101_subset/test/BalanceBeam/v_BalanceBeam_g10_c04.avi
./UCF101_subset/test/BalanceBeam/v_BalanceBeam_g17_c03.avi
./UCF101_subset/test/BalanceBeam/UCF101
./UCF101_subset/test/BalanceBeam/v_BalanceBeam_g22_c04.avi
./UCF101_subset/test/BalanceBeam/v_BalanceBeam_g18_c01.avi
./UCF101_subset/test/BalanceBeam/v_BalanceBeam_g13_c04.avi
./UCF101_subset/test/BalanceBeam/v_BalanceBeam_g08_c02.avi
./UCF101_subset/test/BaseballPitch
./UCF101_subset/test/BaseballPitch/v_BaseballPitch_g25_c03.avi
./UCF101_subset/test/BaseballPitch/v_BaseballPitch_g09_c06.avi
./UCF101_subset/test/BaseballPitch/v_BaseballPitch_g24_c06.avi
./UCF101_subset/test/BaseballPitch/v_BaseballPitch_g18_c02.avi
./UCF101_subset/test/BaseballPitch/UCF101
./UCF101_subset/test/BaseballPitch/v_BaseballPitch_g06_c01.avi
./UCF101_subset/test/BaseballPitch/v_BaseballPitch_g17_c05.avi
./UCF101_subset/test/BaseballPitch/v_BaseballPitch_g25_c05.avi
./UCF101_subset/test/BaseballPitch/v_BaseballPitch_g20_c02.avi
./UCF101_subset/test/BaseballPitch/v_BaseballPitch_g18_c06.avi
./UCF101_subset/test/BaseballPitch/v_BaseballPitch_g04_c01.avi
./UCF101_subset/test/BandMarching
./UCF101_subset/test/BandMarching/v_BandMarching_g02_c02.avi
./UCF101_subset/test/BandMarching/v_BandMarching_g03_c07.avi
./UCF101_subset/test/BandMarching/v_BandMarching_g06_c03.avi
./UCF101_subset/test/BandMarching/v_BandMarching_g05_c02.avi
./UCF101_subset/test/BandMarching/UCF101
./UCF101_subset/test/BandMarching/v_BandMarching_g23_c01.avi
./UCF101_subset/test/BandMarching/v_BandMarching_g01_c07.avi
./UCF101_subset/test/BandMarching/v_BandMarching_g24_c05.avi
./UCF101_subset/test/BandMarching/v_BandMarching_g08_c02.avi
./UCF101_subset/test/BandMarching/v_BandMarching_g10_c04.avi
./UCF101_subset/test/BandMarching/v_BandMarching_g09_c05.avi
./UCF101_subset/test/Archery
./UCF101_subset/test/Archery/v_Archery_g08_c01.avi
./UCF101_subset/test/Archery/v_Archery_g15_c02.avi
./UCF101_subset/test/Archery/v_Archery_g06_c01.avi
./UCF101_subset/test/Archery/v_Archery_g21_c04.avi
./UCF101_subset/test/Archery/v_Archery_g24_c04.avi
./UCF101_subset/test/Archery/v_Archery_g10_c07.avi
./UCF101_subset/test/Archery/v_Archery_g23_c01.avi
./UCF101_subset/test/Archery/UCF101
./UCF101_subset/test/Archery/v_Archery_g18_c04.avi
./UCF101_subset/test/Archery/v_Archery_g16_c05.avi
./UCF101_subset/test/Archery/v_Archery_g03_c02.avi
./UCF101_subset/train
./UCF101_subset/train/BenchPress
./UCF101_subset/train/BenchPress/v_BenchPress_g07_c02.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g24_c01.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g08_c05.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g05_c04.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g16_c01.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g04_c05.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g03_c02.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g02_c01.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g02_c05.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g17_c02.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g25_c02.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g21_c03.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g09_c04.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g20_c04.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g13_c01.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g25_c04.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g13_c05.avi
./UCF101_subset/train/BenchPress/UCF101
./UCF101_subset/train/BenchPress/v_BenchPress_g05_c06.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g21_c01.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g18_c01.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g02_c03.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g18_c03.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g18_c05.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g03_c04.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g07_c06.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g11_c03.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g16_c05.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g10_c01.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g08_c03.avi
./UCF101_subset/train/BenchPress/v_BenchPress_g01_c05.avi
./UCF101_subset/train/BabyCrawling
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g21_c04.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g11_c01.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g11_c03.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g03_c03.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g24_c05.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g09_c06.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g19_c02.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g21_c02.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g22_c04.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g18_c02.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g12_c05.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g20_c03.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g15_c03.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g17_c03.avi
./UCF101_subset/train/BabyCrawling/UCF101
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g06_c04.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g09_c02.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g09_c04.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g25_c03.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g04_c01.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g13_c01.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g05_c03.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g01_c01.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g06_c06.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g10_c02.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g22_c06.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g23_c03.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g03_c01.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g13_c03.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g08_c02.avi
./UCF101_subset/train/BabyCrawling/v_BabyCrawling_g20_c01.avi
./UCF101_subset/train/BasketballDunk
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g21_c01.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g06_c01.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g11_c02.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g11_c04.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g10_c01.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g20_c05.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g01_c04.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g20_c03.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g03_c05.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g15_c07.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g25_c01.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g15_c03.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g12_c03.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g01_c02.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g16_c02.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g23_c03.avi
./UCF101_subset/train/BasketballDunk/UCF101
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g08_c05.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g25_c03.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g08_c03.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g17_c04.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g24_c04.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g22_c03.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g23_c05.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g03_c03.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g04_c03.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g18_c01.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g10_c05.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g05_c01.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g09_c02.avi
./UCF101_subset/train/BasketballDunk/v_BasketballDunk_g17_c02.avi
./UCF101_subset/train/ApplyEyeMakeup
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g16_c03.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g04_c03.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g13_c03.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g19_c04.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g12_c05.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g02_c01.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g10_c03.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g02_c03.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g07_c06.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g11_c04.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g06_c05.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c01.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g18_c03.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c03.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g23_c04.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g05_c06.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g07_c02.avi
./UCF101_subset/train/ApplyEyeMakeup/UCF101
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g14_c01.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g14_c05.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g09_c02.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g18_c05.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c05.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g04_c07.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g16_c05.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g10_c05.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g20_c04.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g25_c01.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c01.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g14_c03.avi
./UCF101_subset/train/ApplyEyeMakeup/v_ApplyEyeMakeup_g22_c05.avi
./UCF101_subset/train/Basketball
./UCF101_subset/train/Basketball/v_Basketball_g20_c06.avi
./UCF101_subset/train/Basketball/v_Basketball_g21_c05.avi
./UCF101_subset/train/Basketball/v_Basketball_g03_c04.avi
./UCF101_subset/train/Basketball/v_Basketball_g01_c07.avi
./UCF101_subset/train/Basketball/v_Basketball_g24_c04.avi
./UCF101_subset/train/Basketball/v_Basketball_g10_c05.avi
./UCF101_subset/train/Basketball/v_Basketball_g19_c07.avi
./UCF101_subset/train/Basketball/v_Basketball_g19_c03.avi
./UCF101_subset/train/Basketball/v_Basketball_g22_c01.avi
./UCF101_subset/train/Basketball/v_Basketball_g15_c07.avi
./UCF101_subset/train/Basketball/v_Basketball_g06_c02.avi
./UCF101_subset/train/Basketball/v_Basketball_g03_c06.avi
./UCF101_subset/train/Basketball/v_Basketball_g16_c04.avi
./UCF101_subset/train/Basketball/v_Basketball_g02_c04.avi
./UCF101_subset/train/Basketball/UCF101
./UCF101_subset/train/Basketball/v_Basketball_g10_c01.avi
./UCF101_subset/train/Basketball/v_Basketball_g15_c05.avi
./UCF101_subset/train/Basketball/v_Basketball_g14_c02.avi
./UCF101_subset/train/Basketball/v_Basketball_g21_c03.avi
./UCF101_subset/train/Basketball/v_Basketball_g04_c04.avi
./UCF101_subset/train/Basketball/v_Basketball_g15_c01.avi
./UCF101_subset/train/Basketball/v_Basketball_g13_c04.avi
./UCF101_subset/train/Basketball/v_Basketball_g01_c03.avi
./UCF101_subset/train/Basketball/v_Basketball_g25_c02.avi
./UCF101_subset/train/Basketball/v_Basketball_g17_c04.avi
./UCF101_subset/train/Basketball/v_Basketball_g22_c05.avi
./UCF101_subset/train/Basketball/v_Basketball_g22_c03.avi
./UCF101_subset/train/Basketball/v_Basketball_g07_c04.avi
./UCF101_subset/train/Basketball/v_Basketball_g03_c02.avi
./UCF101_subset/train/Basketball/v_Basketball_g11_c04.avi
./UCF101_subset/train/Basketball/v_Basketball_g14_c04.avi
./UCF101_subset/train/ApplyLipstick
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g03_c01.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g20_c04.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g10_c02.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g13_c03.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g17_c03.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g15_c03.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g11_c02.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g25_c02.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g24_c05.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g04_c01.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g17_c01.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g18_c04.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g10_c04.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g04_c03.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g06_c05.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g04_c05.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g15_c05.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g12_c02.avi
./UCF101_subset/train/ApplyLipstick/UCF101
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g08_c04.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g19_c04.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g22_c04.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g02_c01.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g09_c02.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g23_c01.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g20_c02.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g03_c03.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g13_c01.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g14_c03.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g05_c04.avi
./UCF101_subset/train/ApplyLipstick/v_ApplyLipstick_g17_c05.avi
./UCF101_subset/train/BalanceBeam
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g12_c02.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g03_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g16_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g04_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g08_c04.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g20_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g25_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g15_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g13_c02.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g21_c03.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g20_c03.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g17_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g24_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g04_c03.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g07_c04.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g09_c02.avi
./UCF101_subset/train/BalanceBeam/UCF101
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g23_c02.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g05_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g05_c03.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g03_c03.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g19_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g06_c07.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g10_c02.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g14_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g14_c03.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g25_c03.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g22_c02.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g21_c01.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g17_c05.avi
./UCF101_subset/train/BalanceBeam/v_BalanceBeam_g12_c04.avi
./UCF101_subset/train/BaseballPitch
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g04_c03.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g10_c05.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g19_c01.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g14_c04.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g19_c05.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g06_c07.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g13_c03.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g16_c03.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g08_c01.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g22_c02.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g13_c07.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g25_c01.avi
./UCF101_subset/train/BaseballPitch/UCF101
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g17_c01.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g09_c04.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g05_c04.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g16_c05.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g24_c04.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g19_c03.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g01_c04.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g16_c01.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g24_c02.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g10_c01.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g21_c04.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g01_c02.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g17_c07.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g23_c07.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g18_c04.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g10_c03.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g08_c03.avi
./UCF101_subset/train/BaseballPitch/v_BaseballPitch_g15_c02.avi
./UCF101_subset/train/BandMarching
./UCF101_subset/train/BandMarching/v_BandMarching_g21_c06.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g04_c02.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g20_c02.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g20_c06.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g16_c04.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g17_c01.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g07_c03.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g03_c03.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g24_c01.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g20_c04.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g19_c05.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g15_c07.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g06_c01.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g18_c03.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g01_c05.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g23_c05.avi
./UCF101_subset/train/BandMarching/UCF101
./UCF101_subset/train/BandMarching/v_BandMarching_g25_c05.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g21_c04.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g01_c03.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g19_c03.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g07_c01.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g25_c01.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g05_c04.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g14_c05.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g24_c03.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g09_c03.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g19_c07.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g04_c04.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g18_c01.avi
./UCF101_subset/train/BandMarching/v_BandMarching_g08_c06.avi
./UCF101_subset/train/Archery
./UCF101_subset/train/Archery/v_Archery_g16_c03.avi
./UCF101_subset/train/Archery/v_Archery_g14_c02.avi
./UCF101_subset/train/Archery/v_Archery_g08_c05.avi
./UCF101_subset/train/Archery/v_Archery_g06_c05.avi
./UCF101_subset/train/Archery/v_Archery_g05_c04.avi
./UCF101_subset/train/Archery/v_Archery_g18_c06.avi
./UCF101_subset/train/Archery/v_Archery_g02_c05.avi
./UCF101_subset/train/Archery/v_Archery_g10_c03.avi
./UCF101_subset/train/Archery/v_Archery_g22_c04.avi
./UCF101_subset/train/Archery/v_Archery_g13_c05.avi
./UCF101_subset/train/Archery/v_Archery_g01_c04.avi
./UCF101_subset/train/Archery/v_Archery_g20_c01.avi
./UCF101_subset/train/Archery/v_Archery_g05_c02.avi
./UCF101_subset/train/Archery/v_Archery_g23_c05.avi
./UCF101_subset/train/Archery/v_Archery_g21_c02.avi
./UCF101_subset/train/Archery/v_Archery_g03_c04.avi
./UCF101_subset/train/Archery/v_Archery_g23_c07.avi
./UCF101_subset/train/Archery/v_Archery_g07_c05.avi
./UCF101_subset/train/Archery/v_Archery_g10_c01.avi
./UCF101_subset/train/Archery/v_Archery_g20_c05.avi
./UCF101_subset/train/Archery/UCF101
./UCF101_subset/train/Archery/v_Archery_g04_c01.avi
./UCF101_subset/train/Archery/v_Archery_g02_c03.avi
./UCF101_subset/train/Archery/v_Archery_g16_c01.avi
./UCF101_subset/train/Archery/v_Archery_g13_c07.avi
./UCF101_subset/train/Archery/v_Archery_g13_c03.avi
./UCF101_subset/train/Archery/v_Archery_g09_c02.avi
./UCF101_subset/train/Archery/v_Archery_g11_c06.avi
./UCF101_subset/train/Archery/v_Archery_g07_c03.avi
./UCF101_subset/train/Archery/v_Archery_g02_c01.avi
./UCF101_subset/train/Archery/v_Archery_g10_c05.avi

从每个视频文件创建帧

frames_from_video_file 函数会将视频拆分为帧,从视频文件中读取随机选择的 n_frames 跨度,并将它们作为 NumPy array 返回。要减少内存和计算开销,请选择少量帧。此外,请从每个视频中选取相同数量的帧,这样可以更轻松地处理批量数据。

def format_frames(frame, output_size):
  """
    Pad and resize an image from a video.

    Args:
      frame: Image that needs to resized and padded. 
      output_size: Pixel size of the output frame image.

    Return:
      Formatted frame with padding of specified output size.
  """
  frame = tf.image.convert_image_dtype(frame, tf.float32)
  frame = tf.image.resize_with_pad(frame, *output_size)
  return frame
def frames_from_video_file(video_path, n_frames, output_size = (224,224), frame_step = 15):
  """
    Creates frames from each video file present for each category.

    Args:
      video_path: File path to the video.
      n_frames: Number of frames to be created per video file.
      output_size: Pixel size of the output frame image.

    Return:
      An NumPy array of frames in the shape of (n_frames, height, width, channels).
  """
  # Read each video frame by frame
  result = []
  src = cv2.VideoCapture(str(video_path))  

  video_length = src.get(cv2.CAP_PROP_FRAME_COUNT)

  need_length = 1 + (n_frames - 1) * frame_step

  if need_length > video_length:
    start = 0
  else:
    max_start = video_length - need_length
    start = random.randint(0, max_start + 1)

  src.set(cv2.CAP_PROP_POS_FRAMES, start)
  # ret is a boolean indicating whether read was successful, frame is the image itself
  ret, frame = src.read()
  result.append(format_frames(frame, output_size))

  for _ in range(n_frames - 1):
    for _ in range(frame_step):
      ret, frame = src.read()
    if ret:
      frame = format_frames(frame, output_size)
      result.append(frame)
    else:
      result.append(np.zeros_like(result[0]))
  src.release()
  result = np.array(result)[..., [2, 1, 0]]

  return result

呈现视频数据

frames_from_video_file 函数会将一组帧作为 NumPy 数组返回。尝试在 Patrick Gillett 的 Wikimedia 的新视频中使用此函数:

curl -O https://upload.wikimedia.org/wikipedia/commons/8/86/End_of_a_jam.ogv
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 55.0M  100 55.0M    0     0  25.5M      0  0:00:02  0:00:02 --:--:-- 25.5M
video_path = "End_of_a_jam.ogv"
sample_video = frames_from_video_file(video_path, n_frames = 10)
sample_video.shape
(10, 224, 224, 3)
def to_gif(images):
  converted_images = np.clip(images * 255, 0, 255).astype(np.uint8)
  imageio.mimsave('./animation.gif', converted_images, fps=10)
  return embed.embed_file('./animation.gif')
to_gif(sample_video)

gif

除了查看此视频外,您还可以显示 UCF-101 数据。为此,请运行以下代码:

# docs-infra: no-execute
ucf_sample_video = frames_from_video_file(next(subset_paths['train'].glob('*/*.avi')), 50)
to_gif(ucf_sample_video)

接下来,定义 FrameGenerator 类以创建一个可迭代对象,该对象可以将数据输入 TensorFlow 数据流水线。生成器 (__call__) 函数产生由 frames_from_video_file 生成的帧数组以及与帧集相关联的标签的独热编码向量。

class FrameGenerator:
  def __init__(self, path, n_frames, training = False):
    """ Returns a set of frames with their associated label. 

      Args:
        path: Video file paths.
        n_frames: Number of frames. 
        training: Boolean to determine if training dataset is being created.
    """
    self.path = path
    self.n_frames = n_frames
    self.training = training
    self.class_names = sorted(set(p.name for p in self.path.iterdir() if p.is_dir()))
    self.class_ids_for_name = dict((name, idx) for idx, name in enumerate(self.class_names))

  def get_files_and_class_names(self):
    video_paths = list(self.path.glob('*/*.avi'))
    classes = [p.parent.name for p in video_paths] 
    return video_paths, classes

  def __call__(self):
    video_paths, classes = self.get_files_and_class_names()

    pairs = list(zip(video_paths, classes))

    if self.training:
      random.shuffle(pairs)

    for path, name in pairs:
      video_frames = frames_from_video_file(path, self.n_frames) 
      label = self.class_ids_for_name[name] # Encode labels
      yield video_frames, label

在将 FrameGenerator 对象封装为 TensorFlow Dataset 对象之前对其进行测试。此外,对于训练数据集,请确保启用训练模式,以便对数据进行重排。

fg = FrameGenerator(subset_paths['train'], 10, training=True)

frames, label = next(fg())

print(f"Shape: {frames.shape}")
print(f"Label: {label}")
Shape: (10, 224, 224, 3)
Label: 3

最后,创建一个 TensorFlow 数据输入流水线。您从生成器对象创建的此流水线允许您将数据输入深度学习模型。在此视频流水线中,每个元素都是一组单独的帧及其关联标签。

# Create the training set
output_signature = (tf.TensorSpec(shape = (None, None, None, 3), dtype = tf.float32),
                    tf.TensorSpec(shape = (), dtype = tf.int16))
train_ds = tf.data.Dataset.from_generator(FrameGenerator(subset_paths['train'], 10, training=True),
                                          output_signature = output_signature)

检查标签是否重排。

for frames, labels in train_ds.take(10):
  print(labels)
tf.Tensor(0, shape=(), dtype=int16)
tf.Tensor(1, shape=(), dtype=int16)
tf.Tensor(9, shape=(), dtype=int16)
tf.Tensor(9, shape=(), dtype=int16)
tf.Tensor(0, shape=(), dtype=int16)
tf.Tensor(0, shape=(), dtype=int16)
tf.Tensor(5, shape=(), dtype=int16)
tf.Tensor(4, shape=(), dtype=int16)
tf.Tensor(9, shape=(), dtype=int16)
tf.Tensor(2, shape=(), dtype=int16)
# Create the validation set
val_ds = tf.data.Dataset.from_generator(FrameGenerator(subset_paths['val'], 10),
                                        output_signature = output_signature)
# Print the shapes of the data
train_frames, train_labels = next(iter(train_ds))
print(f'Shape of training set of frames: {train_frames.shape}')
print(f'Shape of training labels: {train_labels.shape}')

val_frames, val_labels = next(iter(val_ds))
print(f'Shape of validation set of frames: {val_frames.shape}')
print(f'Shape of validation labels: {val_labels.shape}')
Shape of training set of frames: (10, 224, 224, 3)
Shape of training labels: ()
Shape of validation set of frames: (10, 224, 224, 3)
Shape of validation labels: ()

配置数据集以提高性能

使用缓冲预提取,以便从磁盘产生数据,而不会阻塞 I/O。下面是可以在加载数据时使用的两个重要函数:

  • Dataset.cache:在第一个周期期间从磁盘加载图像后,它会将这些图像保留在内存中。该函数确保在训练模型时数据集不会成为瓶颈。如果数据集太大无法装入内存,您也可以使用此方法创建高性能的磁盘缓存。

  • Dataset.prefetch:在训练时重叠数据预处理和模型执行。有关详细信息,请参阅使用 tf.data 提升性能

AUTOTUNE = tf.data.AUTOTUNE

train_ds = train_ds.cache().shuffle(1000).prefetch(buffer_size = AUTOTUNE)
val_ds = val_ds.cache().shuffle(1000).prefetch(buffer_size = AUTOTUNE)

要准备馈送到模型的数据,请使用批处理,如下所示。请注意,在处理视频数据(例如 AVI 文件)时,数据应形成五维对象。这些维度如下:[batch_size, number_of_frames, height, width, channels]。相比之下,图像将具有四个维度:[batch_size, height, width, channels]。下图说明了如何表示视频数据的形状。

视频数据形状

train_ds = train_ds.batch(2)
val_ds = val_ds.batch(2)

train_frames, train_labels = next(iter(train_ds))
print(f'Shape of training set of frames: {train_frames.shape}')
print(f'Shape of training labels: {train_labels.shape}')

val_frames, val_labels = next(iter(val_ds))
print(f'Shape of validation set of frames: {val_frames.shape}')
print(f'Shape of validation labels: {val_labels.shape}')
Shape of training set of frames: (2, 10, 224, 224, 3)
Shape of training labels: (2,)
Shape of validation set of frames: (2, 10, 224, 224, 3)
Shape of validation labels: (2,)

后续步骤

现在,您已经创建了带有标签的视频帧的 TensorFlow Dataset,您可以将其与深度学习模型一起使用。以下使用预训练的 EfficientNet 的分类模型可在几分钟内训练到较高准确率:

net = tf.keras.applications.EfficientNetB0(include_top = False)
net.trainable = False

model = tf.keras.Sequential([
    tf.keras.layers.Rescaling(scale=255),
    tf.keras.layers.TimeDistributed(net),
    tf.keras.layers.Dense(10),
    tf.keras.layers.GlobalAveragePooling3D()
])

model.compile(optimizer = 'adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits = True),
              metrics=['accuracy'])

model.fit(train_ds, 
          epochs = 10,
          validation_data = val_ds,
          callbacks = tf.keras.callbacks.EarlyStopping(patience = 2, monitor = 'val_loss'))
Downloading data from https://storage.googleapis.com/keras-applications/efficientnetb0_notop.h5
16705208/16705208 [==============================] - 0s 0us/step
Epoch 1/10
2023-11-07 23:39:10.086724: E tensorflow/core/grappler/optimizers/meta_optimizer.cc:961] layout failed: INVALID_ARGUMENT: Size of values 0 does not match size of permutation 4 @ fanin shape insequential/time_distributed/efficientnetb0/block2b_drop/dropout/SelectV2-2-TransposeNHWCToNCHW-LayoutOptimizer
2/Unknown - 11s 53ms/step - loss: 2.5284 - accuracy: 0.0000e+00
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1699400352.000239  555168 device_compiler.h:186] Compiled cluster using XLA!  This line is logged at most once for the lifetime of the process.
150/150 [==============================] - 23s 80ms/step - loss: 1.1324 - accuracy: 0.7433 - val_loss: 0.5808 - val_accuracy: 0.8200
Epoch 2/10
150/150 [==============================] - 8s 51ms/step - loss: 0.3391 - accuracy: 0.9633 - val_loss: 0.3407 - val_accuracy: 0.9300
Epoch 3/10
150/150 [==============================] - 8s 51ms/step - loss: 0.1864 - accuracy: 0.9900 - val_loss: 0.2591 - val_accuracy: 0.9500
Epoch 4/10
150/150 [==============================] - 8s 51ms/step - loss: 0.1216 - accuracy: 0.9933 - val_loss: 0.2290 - val_accuracy: 0.9300
Epoch 5/10
150/150 [==============================] - 8s 52ms/step - loss: 0.0864 - accuracy: 0.9967 - val_loss: 0.2058 - val_accuracy: 0.9300
Epoch 6/10
150/150 [==============================] - 8s 52ms/step - loss: 0.0642 - accuracy: 1.0000 - val_loss: 0.1802 - val_accuracy: 0.9600
Epoch 7/10
150/150 [==============================] - 8s 52ms/step - loss: 0.0510 - accuracy: 1.0000 - val_loss: 0.1728 - val_accuracy: 0.9400
Epoch 8/10
150/150 [==============================] - 8s 53ms/step - loss: 0.0399 - accuracy: 1.0000 - val_loss: 0.1640 - val_accuracy: 0.9400
Epoch 9/10
150/150 [==============================] - 8s 53ms/step - loss: 0.0332 - accuracy: 1.0000 - val_loss: 0.1593 - val_accuracy: 0.9400
Epoch 10/10
150/150 [==============================] - 8s 53ms/step - loss: 0.0275 - accuracy: 1.0000 - val_loss: 0.1507 - val_accuracy: 0.9500
<keras.src.callbacks.History at 0x7f8265014160>

要详细了解如何在 TensorFlow 中处理视频数据,请查看以下教程: