Skip to content

Commit 47b9b81

Browse files
jpuigcervercopybara-github
authored andcommitted
Add v2.0.0 Cars Dataset to TFDS, now with test labels.
PiperOrigin-RevId: 282351301
1 parent 08f91c8 commit 47b9b81

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

tensorflow_datasets/image/cars196.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
'Volkswagen Golf Hatchback 2012', 'Volkswagen Golf Hatchback 1991',
134134
'Volkswagen Beetle Hatchback 2012', 'Volvo C30 Hatchback 2012',
135135
'Volvo 240 Sedan 1993', 'Volvo XC90 SUV 2007',
136-
'smart fortwo Convertible 2012'
136+
'smart fortwo Convertible 2012',
137137
]
138138

139139
_CITATION = """\
@@ -152,17 +152,21 @@
152152
class Cars196(tfds.core.GeneratorBasedBuilder):
153153
"""Car Images dataset."""
154154

155-
VERSION = tfds.core.Version('1.1.0')
155+
VERSION = tfds.core.Version('2.0.0')
156+
157+
SUPPORTED_VERSIONS = [
158+
tfds.core.Version('1.1.0'), # Version with no test labels.
159+
]
156160

157161
def _info(self):
158162
"""Define the dataset info."""
159-
163+
names = _NAMES + ['test'] if self.version < '2.0.0' else _NAMES
160164
return tfds.core.DatasetInfo(
161165
builder=self,
162166
description=(_DESCRIPTION),
163167
features=tfds.features.FeaturesDict({
164168
'image': tfds.features.Image(),
165-
'label': tfds.features.ClassLabel(names=_NAMES),
169+
'label': tfds.features.ClassLabel(names=names),
166170
'bbox': tfds.features.BBoxFeature(),
167171
}),
168172
supervised_keys=('image', 'label'),
@@ -175,6 +179,8 @@ def _split_generators(self, dl_manager):
175179
'train': urllib.parse.urljoin(_URL, 'cars_train.tgz'),
176180
'test': urllib.parse.urljoin(_URL, 'cars_test.tgz'),
177181
'extra': _EXTRA_URL,
182+
'test_annos':
183+
urllib.parse.urljoin(_URL, 'cars_test_annos_withlabels.mat'),
178184
})
179185

180186
return [
@@ -198,9 +204,7 @@ def _split_generators(self, dl_manager):
198204
'test',
199205
'data_dir_path':
200206
os.path.join(output_files['test'], 'cars_test'),
201-
'data_annotations_path':
202-
os.path.join(output_files['extra'],
203-
os.path.join('devkit', 'cars_test_annos.mat')),
207+
'data_annotations_path': output_files['test_annos'],
204208
},
205209
),
206210
]
@@ -215,9 +219,10 @@ def _generate_examples(self, split_name, data_dir_path,
215219
mat = tfds.core.lazy_imports.scipy.io.loadmat(f)
216220
for example in mat['annotations'][0]:
217221
image_name = example[-1].item().split('.')[0]
218-
# -1 because class labels are index-1 based.
219-
# There are no labels in the "test" split.
220-
label = -1 if split_name == 'test' else _NAMES[example[4].item() - 1]
222+
if self.version < '2.0.0' and split_name == 'test':
223+
label = -1
224+
else:
225+
label = _NAMES[example[4].item() - 1]
221226
image = image_dict[image_name]
222227
bbox = bbox_dict[image_name]
223228
yield image_name, {

tensorflow_datasets/image/cars196_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@
2020
import tensorflow_datasets.testing as tfds_test
2121

2222

23-
class BinaryAlphaDigitsTest(tfds_test.DatasetBuilderTestCase):
23+
class Cars196Test(tfds_test.DatasetBuilderTestCase):
2424
DATASET_CLASS = cars196.Cars196
2525
SPLITS = {'train': 2, 'test': 2}
2626

27-
DL_EXTRACT_RESULT = {'train': 'train', 'test': 'test', 'extra': 'extra'}
27+
DL_EXTRACT_RESULT = {
28+
'train': 'train',
29+
'test': 'test',
30+
'extra': 'extra',
31+
'test_annos': 'cars_test_annos_withlabels.mat'
32+
}
2833

2934

3035
if __name__ == '__main__':
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
http://imagenet.stanford.edu/internal/car196/cars_test.tgz 977350468 bffea656d6f425cba3c91c6d83336e4c5f86c6cffd8975b0f375d3a10da8e243
2+
http://imagenet.stanford.edu/internal/car196/cars_test_annos_withlabels.mat 185758 790f75be8ea34eeded134cc559332baf23e30e91367e9ddca97d26ed9b895f05
23
http://imagenet.stanford.edu/internal/car196/cars_train.tgz 979269282 512b227b30e2f0a8aab9e09485786ab4479582073a144998da74d64b801fd288
34
https://ai.stanford.edu/~jkrause/cars/car_devkit.tgz 330960 b97deb463af7d58b6bfaa18b2a4de9829f0f79e8ce663dfa9261bf7810e9accd

0 commit comments

Comments
 (0)