Datasets:
ArXiv:
License:
Update the COCO.py type mismatches between the HuggingFace Datasets API and this code
#5
by
Qybera
- opened
COCO.py
CHANGED
|
@@ -126,12 +126,21 @@ class COCO(datasets.GeneratorBasedBuilder):
|
|
| 126 |
)
|
| 127 |
|
| 128 |
def _split_generators(self, dl_manager):
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
return [
|
| 133 |
datasets.SplitGenerator(
|
| 134 |
-
name=
|
| 135 |
gen_kwargs={
|
| 136 |
"annotation_file": annotation_file,
|
| 137 |
"image_folders": image_folders,
|
|
@@ -139,7 +148,7 @@ class COCO(datasets.GeneratorBasedBuilder):
|
|
| 139 |
},
|
| 140 |
),
|
| 141 |
datasets.SplitGenerator(
|
| 142 |
-
name=
|
| 143 |
gen_kwargs={
|
| 144 |
"annotation_file": annotation_file,
|
| 145 |
"image_folders": image_folders,
|
|
@@ -147,7 +156,7 @@ class COCO(datasets.GeneratorBasedBuilder):
|
|
| 147 |
},
|
| 148 |
),
|
| 149 |
datasets.SplitGenerator(
|
| 150 |
-
name=
|
| 151 |
gen_kwargs={
|
| 152 |
"annotation_file": annotation_file,
|
| 153 |
"image_folders": image_folders,
|
|
@@ -239,3 +248,4 @@ class COCO(datasets.GeneratorBasedBuilder):
|
|
| 239 |
"cocoid": image_metadata["cocoid"],
|
| 240 |
}
|
| 241 |
counter += 1
|
|
|
|
|
|
| 126 |
)
|
| 127 |
|
| 128 |
def _split_generators(self, dl_manager):
|
| 129 |
+
annotation_dir = dl_manager.download_and_extract(_KARPATHY_FILES_URL)
|
| 130 |
+
# If annotation_dir is a list, get the first element
|
| 131 |
+
if isinstance(annotation_dir, list):
|
| 132 |
+
annotation_dir = annotation_dir[0]
|
| 133 |
+
annotation_file = os.path.join(annotation_dir, "dataset_coco.json")
|
| 134 |
+
image_folders = dl_manager.download_and_extract(_IMAGES_URLS)
|
| 135 |
+
# If image_folders is a list, convert to dict with split keys
|
| 136 |
+
if isinstance(image_folders, list):
|
| 137 |
+
image_folders = {k: Path(v) for k, v in zip(_IMAGES_URLS.keys(), image_folders)}
|
| 138 |
+
else:
|
| 139 |
+
image_folders = {k: Path(v) for k, v in image_folders.items()}
|
| 140 |
|
| 141 |
return [
|
| 142 |
datasets.SplitGenerator(
|
| 143 |
+
name="train",
|
| 144 |
gen_kwargs={
|
| 145 |
"annotation_file": annotation_file,
|
| 146 |
"image_folders": image_folders,
|
|
|
|
| 148 |
},
|
| 149 |
),
|
| 150 |
datasets.SplitGenerator(
|
| 151 |
+
name="validation",
|
| 152 |
gen_kwargs={
|
| 153 |
"annotation_file": annotation_file,
|
| 154 |
"image_folders": image_folders,
|
|
|
|
| 156 |
},
|
| 157 |
),
|
| 158 |
datasets.SplitGenerator(
|
| 159 |
+
name="test",
|
| 160 |
gen_kwargs={
|
| 161 |
"annotation_file": annotation_file,
|
| 162 |
"image_folders": image_folders,
|
|
|
|
| 248 |
"cocoid": image_metadata["cocoid"],
|
| 249 |
}
|
| 250 |
counter += 1
|
| 251 |
+
|