Skip to content

Commit 0e1d588

Browse files
author
The TensorFlow Datasets Authors
committed
Support huggingface Video feature
PiperOrigin-RevId: 770677201
1 parent 56fea7b commit 0e1d588

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

tensorflow_datasets/core/features/video_feature.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Video(sequence_feature.Sequence):
9393

9494
def __init__(
9595
self,
96-
shape: Sequence[Optional[int]],
96+
shape: Sequence[Optional[int]] | None = None,
9797
encoding_format: str = 'png',
9898
ffmpeg_extra_args: Sequence[str] = (),
9999
use_colormap: bool = False,
@@ -121,19 +121,22 @@ def __init__(
121121
ValueError: If the shape is invalid
122122
"""
123123
dtype = tf.dtypes.as_dtype(dtype)
124-
shape = tuple(shape)
125-
if len(shape) != 4:
126-
raise ValueError('Video shape should be of rank 4')
124+
img_shape = None
125+
if shape:
126+
shape = tuple(shape)
127+
if len(shape) != 4:
128+
raise ValueError('Video shape should be of rank 4')
129+
img_shape = shape[1:]
127130
self._encoding_format = encoding_format
128131
self._extra_ffmpeg_args = list(ffmpeg_extra_args or [])
129132
super(Video, self).__init__(
130133
image_feature.Image(
131-
shape=shape[1:],
134+
shape=img_shape,
132135
dtype=dtype,
133136
encoding_format=encoding_format,
134137
use_colormap=use_colormap,
135138
),
136-
length=shape[0],
139+
length=shape[0] if shape else None,
137140
)
138141

139142
def _ffmpeg_decode(self, path_or_fobj):

tensorflow_datasets/core/utils/huggingface_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ def convert_hf_features(hf_features) -> feature_lib.FeatureConnector:
119119
sample_rate=hf_features.sampling_rate,
120120
dtype=np.int32,
121121
)
122+
case hf_datasets.Video():
123+
return feature_lib.Video()
122124

123125
raise TypeError(f'Type {type(hf_features)} is not supported.')
124126

0 commit comments

Comments
 (0)