Skip to content

Commit 4d7355b

Browse files
pierrot0copybara-github
authored andcommitted
Ucf101 dataset: add S3 version (non default yet).
PiperOrigin-RevId: 282941574
1 parent 37fc133 commit 4d7355b

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

tensorflow_datasets/video/ucf101.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ def __init__(self, split_number, width=None, height=None, **kwargs):
7979
self.split_number = split_number
8080

8181

82+
_VERSION = tfds.core.Version(
83+
'1.0.0', experiments={tfds.core.Experiment.S3: False})
84+
_SUPPORTED_VERSIONS = [
85+
tfds.core.Version(
86+
'2.0.0', 'New split API (https://tensorflow.org/datasets/splits)'),
87+
]
88+
89+
8290
class Ucf101(tfds.core.GeneratorBasedBuilder):
8391
"""Ucf101 action recognition dataset.
8492
@@ -93,35 +101,35 @@ class Ucf101(tfds.core.GeneratorBasedBuilder):
93101
width=256,
94102
height=256,
95103
split_number=1,
96-
version=tfds.core.Version(
97-
'1.0.0', experiments={tfds.core.Experiment.S3: False}),
104+
version=_VERSION,
105+
supported_versions=_SUPPORTED_VERSIONS,
98106
),
99107
Ucf101Config(
100108
name='ucf101_1',
101109
description='UCF with the action recognition split #1.',
102110
width=None,
103111
height=None,
104112
split_number=1,
105-
version=tfds.core.Version(
106-
'1.0.0', experiments={tfds.core.Experiment.S3: False}),
113+
version=_VERSION,
114+
supported_versions=_SUPPORTED_VERSIONS,
107115
),
108116
Ucf101Config(
109117
name='ucf101_2',
110118
description='UCF with the action recognition split #2.',
111119
width=None,
112120
height=None,
113121
split_number=2,
114-
version=tfds.core.Version(
115-
'1.0.0', experiments={tfds.core.Experiment.S3: False}),
122+
version=_VERSION,
123+
supported_versions=_SUPPORTED_VERSIONS,
116124
),
117125
Ucf101Config(
118126
name='ucf101_3',
119127
description='UCF with the action recognition split #3.',
120128
width=None,
121129
height=None,
122130
split_number=3,
123-
version=tfds.core.Version(
124-
'1.0.0', experiments={tfds.core.Experiment.S3: False}),
131+
version=_VERSION,
132+
supported_versions=_SUPPORTED_VERSIONS,
125133
),
126134
]
127135

@@ -186,7 +194,7 @@ def _generate_examples(self, videos_dir, splits_dir, data_list):
186194
data_list_path_path = os.path.join(splits_dir, data_list)
187195
with tf.io.gfile.GFile(data_list_path_path, 'r') as data_list_file:
188196
labels_and_paths = data_list_file.readlines()
189-
for label_and_path in labels_and_paths:
197+
for label_and_path in sorted(labels_and_paths):
190198
# The train splits contain not only the filename, but also a digit
191199
# encoding the label separated by a space, which we ignore.
192200
label_and_path = label_and_path.strip().split(' ')[0]
@@ -198,4 +206,4 @@ def _generate_examples(self, videos_dir, splits_dir, data_list):
198206
logging.error('Example %s not found', video_path)
199207
continue
200208
# We extract the label from the filename.
201-
yield {'video': video_path, 'label': label}
209+
yield path, {'video': video_path, 'label': label}

tensorflow_datasets/video/ucf101_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,10 @@ def _assertAsDataset(self, builder):
5454
{'test': {'Archery': 1, 'Nunchucks': 1},
5555
'train': {'Archery': 1, 'Nunchucks': 2}})
5656

57+
58+
class Ucf101S3Test(Ucf101Test):
59+
VERSION = 'experimental_latest'
60+
61+
5762
if __name__ == '__main__':
5863
testing.test_main()

0 commit comments

Comments
 (0)