Update EMT.py
Browse files
EMT.py
CHANGED
|
@@ -69,36 +69,71 @@ class EMT(datasets.GeneratorBasedBuilder):
|
|
| 69 |
"train": _TRAIN_IMAGE_ARCHIVE_URL,
|
| 70 |
"test": _TEST_IMAGE_ARCHIVE_URL,
|
| 71 |
}
|
| 72 |
-
|
| 73 |
annotation_urls = {
|
| 74 |
"train": _TRAIN_ANNOTATION_ARCHIVE_URL,
|
| 75 |
"test": _TEST_ANNOTATION_ARCHIVE_URL,
|
| 76 |
}
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
# Ensure paths are correctly resolved
|
| 79 |
-
extracted_paths = dl_manager.download_and_extract(annotation_urls)
|
| 80 |
-
image_archives = dl_manager.download_and_extract(image_urls)
|
| 81 |
-
|
| 82 |
-
# ✅ Ensure annotation paths point to the correct subdirectory
|
| 83 |
-
train_annotation_path = os.path.join(extracted_paths["train"], "annotations", "train")
|
| 84 |
-
test_annotation_path = os.path.join(extracted_paths["test"], "annotations", "test")
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
return [
|
| 87 |
datasets.SplitGenerator(
|
| 88 |
-
name=datasets.Split.TRAIN,
|
| 89 |
gen_kwargs={
|
| 90 |
-
"images": dl_manager.iter_archive(
|
| 91 |
-
"annotation_path":
|
| 92 |
},
|
| 93 |
),
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
def _generate_examples(self, images, annotation_path):
|
| 104 |
"""Generate dataset examples by matching images to their corresponding annotations."""
|
|
|
|
| 69 |
"train": _TRAIN_IMAGE_ARCHIVE_URL,
|
| 70 |
"test": _TEST_IMAGE_ARCHIVE_URL,
|
| 71 |
}
|
| 72 |
+
|
| 73 |
annotation_urls = {
|
| 74 |
"train": _TRAIN_ANNOTATION_ARCHIVE_URL,
|
| 75 |
"test": _TEST_ANNOTATION_ARCHIVE_URL,
|
| 76 |
}
|
| 77 |
+
|
| 78 |
+
# Based on the requested split, we only download the relevant data
|
| 79 |
+
split = self.config.name # Determine the requested split (train or test)
|
| 80 |
|
| 81 |
+
# Ensure paths are correctly resolved for the requested split
|
| 82 |
+
extracted_paths = dl_manager.download_and_extract({split: annotation_urls[split]})
|
| 83 |
+
image_archives = dl_manager.download_and_extract({split: image_urls[split]})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
# Ensure annotation paths point to the correct subdirectory
|
| 86 |
+
annotation_path = os.path.join(extracted_paths[split], "annotations", split)
|
| 87 |
+
image_path = image_archives[split]
|
| 88 |
+
|
| 89 |
return [
|
| 90 |
datasets.SplitGenerator(
|
| 91 |
+
name=datasets.Split.TRAIN if split == "train" else datasets.Split.TEST,
|
| 92 |
gen_kwargs={
|
| 93 |
+
"images": dl_manager.iter_archive(image_path),
|
| 94 |
+
"annotation_path": annotation_path,
|
| 95 |
},
|
| 96 |
),
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
# def _split_generators(self, dl_manager):
|
| 101 |
+
# """Download (if not cached) and prepare dataset splits."""
|
| 102 |
+
|
| 103 |
+
# image_urls = {
|
| 104 |
+
# "train": _TRAIN_IMAGE_ARCHIVE_URL,
|
| 105 |
+
# "test": _TEST_IMAGE_ARCHIVE_URL,
|
| 106 |
+
# }
|
| 107 |
+
|
| 108 |
+
# annotation_urls = {
|
| 109 |
+
# "train": _TRAIN_ANNOTATION_ARCHIVE_URL,
|
| 110 |
+
# "test": _TEST_ANNOTATION_ARCHIVE_URL,
|
| 111 |
+
# }
|
| 112 |
+
|
| 113 |
+
# # Ensure paths are correctly resolved
|
| 114 |
+
# extracted_paths = dl_manager.download_and_extract(annotation_urls)
|
| 115 |
+
# image_archives = dl_manager.download_and_extract(image_urls)
|
| 116 |
+
|
| 117 |
+
# # ✅ Ensure annotation paths point to the correct subdirectory
|
| 118 |
+
# train_annotation_path = os.path.join(extracted_paths["train"], "annotations", "train")
|
| 119 |
+
# test_annotation_path = os.path.join(extracted_paths["test"], "annotations", "test")
|
| 120 |
+
|
| 121 |
+
# return [
|
| 122 |
+
# datasets.SplitGenerator(
|
| 123 |
+
# name=datasets.Split.TRAIN,
|
| 124 |
+
# gen_kwargs={
|
| 125 |
+
# "images": dl_manager.iter_archive(image_archives["train"]),
|
| 126 |
+
# "annotation_path": train_annotation_path, # ✅ Corrected path
|
| 127 |
+
# },
|
| 128 |
+
# ),
|
| 129 |
+
# datasets.SplitGenerator(
|
| 130 |
+
# name=datasets.Split.TEST,
|
| 131 |
+
# gen_kwargs={
|
| 132 |
+
# "images": dl_manager.iter_archive(image_archives["test"]),
|
| 133 |
+
# "annotation_path": test_annotation_path, # ✅ Corrected path
|
| 134 |
+
# },
|
| 135 |
+
# ),
|
| 136 |
+
# ]
|
| 137 |
|
| 138 |
def _generate_examples(self, images, annotation_path):
|
| 139 |
"""Generate dataset examples by matching images to their corresponding annotations."""
|