Class SequenceDict
Inherits From: FeaturesDict
Defined in core/features/sequence_feature.py
.
Composite FeatureConnector
for a dict
where each value is a list.
SequenceDict
correspond to sequence of tfds.features.FeatureDict
. At
generation time, a list for each of the sequence element is given. The output
of tf.data.Dataset
will batch all the elements of the sequence together.
If the length of the sequence is static and known in advance, it should be
specified in the constructor using the length
param.
Note that SequenceDict
do not support features which are of type
tf.io.FixedLenSequenceFeature
and do not support empty sequences.
Example: At construction time:
tfds.SequenceDict({
'frame': tfds.features.Image(shape=(64, 64, 3))
'action': tfds.features.ClassLabel(['up', 'down', 'left', 'right'])
}, length=NB_FRAME)
During data generation:
yield self.info.encode_example({
'frame': np.ones(shape=(NB_FRAME, 64, 64, 3)),
'action': ['left', 'left', 'up', ...],
})
Tensor returned by .as_dataset()
:
{
'frame': tf.Tensor(shape=(NB_FRAME, 64, 64, 3), dtype=tf.uint8),
'action': tf.Tensor(shape=(NB_FRAME,), dtype=tf.int64),
}
At generation time, you can specify a list of features dict, a dict of list
values or a stacked numpy array. The lists will automatically be distributed
into their corresponding FeatureConnector
.
__init__
__init__(
feature_dict,
length=None,
**kwargs
)
Construct a sequence dict.
Args:
feature_dict
:dict
, the features to wraplength
:int
, length of the sequence if static and known in advance**kwargs
:dict
, constructor kwargs oftfds.features.FeaturesDict
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
__getitem__
__getitem__(key)
Return the feature associated with the key.
__iter__
__iter__()
__len__
__len__()
decode_example
decode_example(tfexample_dict)
encode_example
encode_example(example_dict)
get_serialized_info
get_serialized_info()
See base class for details.
get_tensor_info
get_tensor_info()
See base class for details.
items
items()
keys
keys()
load_metadata
load_metadata(
data_dir,
feature_name=None
)
See base class for details.
save_metadata
save_metadata(
data_dir,
feature_name=None
)
See base class for details.
values
values()