133
133
'Volkswagen Golf Hatchback 2012' , 'Volkswagen Golf Hatchback 1991' ,
134
134
'Volkswagen Beetle Hatchback 2012' , 'Volvo C30 Hatchback 2012' ,
135
135
'Volvo 240 Sedan 1993' , 'Volvo XC90 SUV 2007' ,
136
- 'smart fortwo Convertible 2012'
136
+ 'smart fortwo Convertible 2012' ,
137
137
]
138
138
139
139
_CITATION = """\
152
152
class Cars196 (tfds .core .GeneratorBasedBuilder ):
153
153
"""Car Images dataset."""
154
154
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
+ ]
156
160
157
161
def _info (self ):
158
162
"""Define the dataset info."""
159
-
163
+ names = _NAMES + [ 'test' ] if self . version < '2.0.0' else _NAMES
160
164
return tfds .core .DatasetInfo (
161
165
builder = self ,
162
166
description = (_DESCRIPTION ),
163
167
features = tfds .features .FeaturesDict ({
164
168
'image' : tfds .features .Image (),
165
- 'label' : tfds .features .ClassLabel (names = _NAMES ),
169
+ 'label' : tfds .features .ClassLabel (names = names ),
166
170
'bbox' : tfds .features .BBoxFeature (),
167
171
}),
168
172
supervised_keys = ('image' , 'label' ),
@@ -175,6 +179,8 @@ def _split_generators(self, dl_manager):
175
179
'train' : urllib .parse .urljoin (_URL , 'cars_train.tgz' ),
176
180
'test' : urllib .parse .urljoin (_URL , 'cars_test.tgz' ),
177
181
'extra' : _EXTRA_URL ,
182
+ 'test_annos' :
183
+ urllib .parse .urljoin (_URL , 'cars_test_annos_withlabels.mat' ),
178
184
})
179
185
180
186
return [
@@ -198,9 +204,7 @@ def _split_generators(self, dl_manager):
198
204
'test' ,
199
205
'data_dir_path' :
200
206
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' ],
204
208
},
205
209
),
206
210
]
@@ -215,9 +219,10 @@ def _generate_examples(self, split_name, data_dir_path,
215
219
mat = tfds .core .lazy_imports .scipy .io .loadmat (f )
216
220
for example in mat ['annotations' ][0 ]:
217
221
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 ]
221
226
image = image_dict [image_name ]
222
227
bbox = bbox_dict [image_name ]
223
228
yield image_name , {
0 commit comments