Update test.py
Browse files
test.py
CHANGED
|
@@ -564,13 +564,13 @@ class Food500(datasets.GeneratorBasedBuilder):
|
|
| 564 |
|
| 565 |
def _split_generators(self, dl_manager):
|
| 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:
|
| 571 |
#train_set = set(file_obj.read().split("\n"))
|
| 572 |
#train_set = {path.encode("utf-8") for path in train_set}
|
| 573 |
-
train_set = set(("Abalone/Abalone_0001.jpg".encode("utf-8")))
|
| 574 |
"""if file_path == _VALID_TXT:
|
| 575 |
# valid_set = set(file_obj.read().split("\n"))
|
| 576 |
# valid_set = {path.encode("utf-8") for path in valid_set}
|
|
@@ -586,7 +586,7 @@ class Food500(datasets.GeneratorBasedBuilder):
|
|
| 586 |
name=datasets.Split.TRAIN,
|
| 587 |
gen_kwargs={
|
| 588 |
"images": dl_manager.iter_archive(archive_path),
|
| 589 |
-
"
|
| 590 |
},
|
| 591 |
),
|
| 592 |
"""datasets.SplitGenerator(
|
|
@@ -605,11 +605,13 @@ class Food500(datasets.GeneratorBasedBuilder):
|
|
| 605 |
),"""
|
| 606 |
]
|
| 607 |
|
| 608 |
-
def _generate_examples(self, images,
|
| 609 |
"""Generate images and labels for splits."""
|
|
|
|
|
|
|
| 610 |
for file_path, file_obj in images:
|
| 611 |
if file_path.startswith(_IMAGES_DIR):
|
| 612 |
-
if file_path[len(_IMAGES_DIR) : -len(".jpg")] in
|
| 613 |
label = file_path.split("/")[2]
|
| 614 |
yield file_path, {
|
| 615 |
"image": {"path": file_path, "bytes": file_obj.read()},
|
|
|
|
| 564 |
|
| 565 |
def _split_generators(self, dl_manager):
|
| 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:
|
| 571 |
#train_set = set(file_obj.read().split("\n"))
|
| 572 |
#train_set = {path.encode("utf-8") for path in train_set}
|
| 573 |
+
#train_set = set(("Abalone/Abalone_0001.jpg".encode("utf-8")))
|
| 574 |
"""if file_path == _VALID_TXT:
|
| 575 |
# valid_set = set(file_obj.read().split("\n"))
|
| 576 |
# valid_set = {path.encode("utf-8") for path in valid_set}
|
|
|
|
| 586 |
name=datasets.Split.TRAIN,
|
| 587 |
gen_kwargs={
|
| 588 |
"images": dl_manager.iter_archive(archive_path),
|
| 589 |
+
"metadata_path": "train_feature.txt",
|
| 590 |
},
|
| 591 |
),
|
| 592 |
"""datasets.SplitGenerator(
|
|
|
|
| 605 |
),"""
|
| 606 |
]
|
| 607 |
|
| 608 |
+
def _generate_examples(self, images, metadata_path):
|
| 609 |
"""Generate images and labels for splits."""
|
| 610 |
+
with open(metadata_path, encoding="utf-8") as f:
|
| 611 |
+
files_to_keep = set(f.read().split("\n"))
|
| 612 |
for file_path, file_obj in images:
|
| 613 |
if file_path.startswith(_IMAGES_DIR):
|
| 614 |
+
if file_path[len(_IMAGES_DIR) : -len(".jpg")] in files_to_keep:
|
| 615 |
label = file_path.split("/")[2]
|
| 616 |
yield file_path, {
|
| 617 |
"image": {"path": file_path, "bytes": file_obj.read()},
|