tfds.features.Video

Class Video

FeatureConnector for videos, encoding frames individually on disk.

Inherits From: Sequence

Defined in core/features/video_feature.py.

Video: The image connector accepts as input a 4 dimensional uint8 array representing a video, a sequence of paths to encoded frames, or a path or a file object that can be decoded with ffmpeg. Note that not all formats in ffmpeg support reading from pipes, so providing a file object might fail. Furthermore, if a path is given that is not on the local file system, we first copy it to a temporary local file before passing it to ffmpeg.

Output: video: tf.Tensor of type tf.uint8 and shape [num_frames, height, width, channels], where channels must be 1 or 3

Example: * In the DatasetInfo object: features=features.FeatureDict({ 'video': features.Video(shape=(None, 64, 64, 3)), })

  • During generation:

      yield {
          'input': np.ones(shape=(128, 64, 64, 3), dtype=np.uint8),
      }
    

    or

      yield {
    '      video': ['path/to/frame001.png', 'path/to/frame002.png'],
      }
    

    or

      yield {
            'input': '/path/to/video.avi',
      }
    

    or

      yield {
            'input': gfile.GFile('/complex/path/video.avi'),
      }
    

__init__

__init__(
    shape,
    encoding_format='png',
    ffmpeg_extra_args=()
)

Initializes the connector.

Args:

  • shape: tuple of ints, the shape of the video (num_frames, height, width, channels), where channels is 1 or 3.
  • encoding_format: The video is stored as a sequence of encoded images. You can use any encoding format supported by image_feature.Feature.
  • ffmpeg_extra_args: A sequence of additional args to be passed to the ffmpeg binary. Specifically, ffmpeg will be called as: ffmpeg -i <input_file> <ffmpeg_extra_args> %010d.<encoding_format>

Raises:

  • ValueError: If the shape is invalid

Properties

dtype

Return the dtype (or dict of dtype) of this FeatureConnector.

serialized_keys

List of the flattened feature keys after serialization.

shape

Return the shape (or dict of shape) of this FeatureConnector.

Methods

__getattr__

__getattr__(key)

Allow to access the underlying attributes directly.

__getstate__

__getstate__()

__setstate__

__setstate__(state)

decode_example

decode_example(tfexample_data)

Wrapper around SequenceDict.

encode_example

encode_example(video_or_path_or_fobj)

Converts the given image into a dict convertible to tf example.

get_serialized_info

get_serialized_info()

get_tensor_info

get_tensor_info()

load_metadata

load_metadata(
    data_dir,
    feature_name
)

Restore the feature metadata from disk.

If a dataset is re-loaded and generated files exists on disk, this function will restore the feature metadata from the saved file.

Args:

  • data_dir: str, path to the dataset folder to which save the info (ex: ~/datasets/cifar10/1.2.0/)
  • feature_name: str, the name of the feature (from the FeaturesDict key)

save_metadata

save_metadata(
    data_dir,
    feature_name
)

Save the feature metadata on disk.

This function is called after the data has been generated (by _download_and_prepare) to save the feature connector info with the generated dataset.

Some dataset/features dynamically compute info during _download_and_prepare. For instance:

  • Labels are loaded from the downloaded data
  • Vocabulary is created from the downloaded data
  • ImageLabelFolder compute the image dtypes/shape from the manual_dir

After the info have been added to the feature, this function allow to save those additional info to be restored the next time the data is loaded.

By default, this function do not save anything, but sub-classes can overwrite the function.

Args:

  • data_dir: str, path to the dataset folder to which save the info (ex: ~/datasets/cifar10/1.2.0/)
  • feature_name: str, the name of the feature (from the FeaturesDict key)