simplify script
Browse files- FGVC-Aircraft.py +26 -20
FGVC-Aircraft.py
CHANGED
@@ -265,6 +265,17 @@ _VARIANTS = [
|
|
265 |
]
|
266 |
|
267 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
class FGVCAircraft(datasets.GeneratorBasedBuilder):
|
269 |
|
270 |
VERSION = datasets.Version("1.0.0")
|
@@ -341,37 +352,32 @@ class FGVCAircraft(datasets.GeneratorBasedBuilder):
|
|
341 |
]
|
342 |
|
343 |
def _generate_examples(self, images_dir, annotations_dir, split):
|
344 |
-
|
345 |
-
|
346 |
|
347 |
families = open(annotations_dir / f"images_family_{split}.txt").readlines()
|
348 |
-
families =
|
349 |
|
350 |
manufacturers = open(
|
351 |
annotations_dir / f"images_manufacturer_{split}.txt"
|
352 |
).readlines()
|
353 |
-
|
354 |
-
manufacturers = [
|
355 |
-
" ".join(manufacturer.strip().split()[1:]) for manufacturer in manufacturers
|
356 |
-
]
|
357 |
|
358 |
variants = open(annotations_dir / f"images_variant_{split}.txt").readlines()
|
359 |
-
variants =
|
360 |
|
361 |
bounding_boxes = open(
|
362 |
os.path.join(annotations_dir, "images_box.txt")
|
363 |
).readlines()
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
variant = variants[i]
|
374 |
-
xmin, ymin, xmax, ymax = list(map(int, bboxes[filename.split(".")[0]]))
|
375 |
|
376 |
record = {
|
377 |
"image": str(full_path),
|
@@ -380,4 +386,4 @@ class FGVCAircraft(datasets.GeneratorBasedBuilder):
|
|
380 |
"manufacturer": manufacturer,
|
381 |
"variant": variant,
|
382 |
}
|
383 |
-
yield
|
|
|
265 |
]
|
266 |
|
267 |
|
268 |
+
def parse_annotations(annotations, join_labels=True):
|
269 |
+
annotations = [annotation.strip().split() for annotation in annotations]
|
270 |
+
if join_labels:
|
271 |
+
return {
|
272 |
+
annotation[0].strip(): " ".join(annotation[1:])
|
273 |
+
for annotation in annotations
|
274 |
+
}
|
275 |
+
else:
|
276 |
+
return {annotation[0].strip(): annotation[1:] for annotation in annotations}
|
277 |
+
|
278 |
+
|
279 |
class FGVCAircraft(datasets.GeneratorBasedBuilder):
|
280 |
|
281 |
VERSION = datasets.Version("1.0.0")
|
|
|
352 |
]
|
353 |
|
354 |
def _generate_examples(self, images_dir, annotations_dir, split):
|
355 |
+
image_ids = open(annotations_dir / f"images_{split}.txt").readlines()
|
356 |
+
image_ids = [image_id.strip() for image_id in image_ids]
|
357 |
|
358 |
families = open(annotations_dir / f"images_family_{split}.txt").readlines()
|
359 |
+
families = parse_annotations(families)
|
360 |
|
361 |
manufacturers = open(
|
362 |
annotations_dir / f"images_manufacturer_{split}.txt"
|
363 |
).readlines()
|
364 |
+
manufacturers = parse_annotations(manufacturers)
|
|
|
|
|
|
|
365 |
|
366 |
variants = open(annotations_dir / f"images_variant_{split}.txt").readlines()
|
367 |
+
variants = parse_annotations(variants)
|
368 |
|
369 |
bounding_boxes = open(
|
370 |
os.path.join(annotations_dir, "images_box.txt")
|
371 |
).readlines()
|
372 |
+
|
373 |
+
bounding_boxes = parse_annotations(bounding_boxes, join_labels=False)
|
374 |
+
|
375 |
+
for image_id in image_ids:
|
376 |
+
full_path = images_dir / f"{image_id}.jpg"
|
377 |
+
family = families[image_id]
|
378 |
+
manufacturer = manufacturers[image_id]
|
379 |
+
variant = variants[image_id]
|
380 |
+
xmin, ymin, xmax, ymax = list(map(int, bounding_boxes[image_id]))
|
|
|
|
|
381 |
|
382 |
record = {
|
383 |
"image": str(full_path),
|
|
|
386 |
"manufacturer": manufacturer,
|
387 |
"variant": variant,
|
388 |
}
|
389 |
+
yield image_id, record
|