tfds.features.Sequence

Class Sequence

Similar to tfds.featuresSequenceDict, but only contains a single feature.

Inherits From: FeatureConnector

Defined in core/features/sequence_feature.py.

Ex: In DatasetInfo:

features=tfds.features.FeatureDict({
    'image': tfds.features.Image(),
    'labels': tfds.features.Sequence(tfds.features.ClassLabel(num_classes=5)),
})

At generation time:

yield {
    'image': 'path/to/img.png',
    'labels': [0, 3, 3, 2, 4],
}

Note that the underlying feature attributes can be accessed directly through the sequence.

builder.info.features['labels'].names

__init__

__init__(
    feature,
    **kwargs
)

Construct a sequence from a specific feature.

Args:

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(example_data)

Wrapper around SequenceDict.

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)