Update test.py
Browse files
test.py
CHANGED
|
@@ -566,44 +566,39 @@ class Food500(datasets.GeneratorBasedBuilder):
|
|
| 566 |
archive_path = dl_manager.download(_BASE_URL)
|
| 567 |
split_metadata_path = dl_manager.download(_METADATA_URL)
|
| 568 |
metadata = dl_manager.iter_archive(split_metadata_path)
|
| 569 |
-
train_file = None
|
| 570 |
-
valid_file = None
|
| 571 |
-
test_file = None
|
| 572 |
for file_path, file_obj in metadata:
|
| 573 |
-
if file_path == _TRAIN_TXT:
|
| 574 |
-
if file_path == _VALID_TXT:
|
| 575 |
-
if file_path == _TEST_TXT:
|
| 576 |
-
# pass
|
| 577 |
return [
|
| 578 |
datasets.SplitGenerator(
|
| 579 |
name=datasets.Split.TRAIN,
|
| 580 |
gen_kwargs={
|
| 581 |
"images": dl_manager.iter_archive(archive_path),
|
| 582 |
-
"
|
| 583 |
},
|
| 584 |
),
|
| 585 |
datasets.SplitGenerator(
|
| 586 |
name=datasets.Split.VALIDATION,
|
| 587 |
gen_kwargs={
|
| 588 |
"images": dl_manager.iter_archive(archive_path),
|
| 589 |
-
"
|
| 590 |
},
|
| 591 |
),
|
| 592 |
datasets.SplitGenerator(
|
| 593 |
name=datasets.Split.TEST,
|
| 594 |
gen_kwargs={
|
| 595 |
"images": dl_manager.iter_archive(archive_path),
|
| 596 |
-
"
|
| 597 |
},
|
| 598 |
),
|
| 599 |
]
|
| 600 |
|
| 601 |
-
def _generate_examples(self, images,
|
| 602 |
"""Generate images and labels for splits."""
|
| 603 |
-
files_to_keep = set(metadata_file.read().split("\n"))
|
| 604 |
for file_path, file_obj in images:
|
| 605 |
if file_path.startswith(_IMAGES_DIR):
|
| 606 |
-
if file_path[len(_IMAGES_DIR) : -len(".jpg")] in
|
| 607 |
label = file_path.split("/")[2]
|
| 608 |
yield file_path, {
|
| 609 |
"image": {"path": file_path, "bytes": file_obj.read()},
|
|
|
|
| 566 |
archive_path = dl_manager.download(_BASE_URL)
|
| 567 |
split_metadata_path = dl_manager.download(_METADATA_URL)
|
| 568 |
metadata = dl_manager.iter_archive(split_metadata_path)
|
|
|
|
|
|
|
|
|
|
| 569 |
for file_path, file_obj in metadata:
|
| 570 |
+
if file_path == _TRAIN_TXT: train_set = set(file_obj.read().split("\n"))
|
| 571 |
+
if file_path == _VALID_TXT: valid_set = set(file_obj.read().split("\n"))
|
| 572 |
+
if file_path == _TEST_TXT: test_set = set(file_obj.read().split("\n"))
|
|
|
|
| 573 |
return [
|
| 574 |
datasets.SplitGenerator(
|
| 575 |
name=datasets.Split.TRAIN,
|
| 576 |
gen_kwargs={
|
| 577 |
"images": dl_manager.iter_archive(archive_path),
|
| 578 |
+
"metadata_set": train_set,
|
| 579 |
},
|
| 580 |
),
|
| 581 |
datasets.SplitGenerator(
|
| 582 |
name=datasets.Split.VALIDATION,
|
| 583 |
gen_kwargs={
|
| 584 |
"images": dl_manager.iter_archive(archive_path),
|
| 585 |
+
"metadata_set": valid_set,
|
| 586 |
},
|
| 587 |
),
|
| 588 |
datasets.SplitGenerator(
|
| 589 |
name=datasets.Split.TEST,
|
| 590 |
gen_kwargs={
|
| 591 |
"images": dl_manager.iter_archive(archive_path),
|
| 592 |
+
"metadata_set": test_set,
|
| 593 |
},
|
| 594 |
),
|
| 595 |
]
|
| 596 |
|
| 597 |
+
def _generate_examples(self, images, metadata_set):
|
| 598 |
"""Generate images and labels for splits."""
|
|
|
|
| 599 |
for file_path, file_obj in images:
|
| 600 |
if file_path.startswith(_IMAGES_DIR):
|
| 601 |
+
if file_path[len(_IMAGES_DIR) : -len(".jpg")] in metadata_set:
|
| 602 |
label = file_path.split("/")[2]
|
| 603 |
yield file_path, {
|
| 604 |
"image": {"path": file_path, "bytes": file_obj.read()},
|