Update ecoset.py
Browse files
ecoset.py
CHANGED
@@ -205,17 +205,19 @@ class Ecoset(datasets.GeneratorBasedBuilder):
|
|
205 |
|
206 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
207 |
def _generate_examples(self, archives, split):
|
208 |
-
|
209 |
-
|
|
|
|
|
210 |
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
|
|
205 |
|
206 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
207 |
def _generate_examples(self, archives, split):
|
208 |
+
"""Yields examples."""
|
209 |
+
idx = 0
|
210 |
+
split_archives = os.path.join(archives, split)
|
211 |
+
acceptable_formats = [".JPEG", ".JPG", ".jpeg", ".jpg"]
|
212 |
|
213 |
+
for subdirectory in os.listdir(split_archives):
|
214 |
+
subdirectory_path = os.path.join(split_archives, subdirectory)
|
215 |
+
if os.path.isdir(subdirectory_path):
|
216 |
+
label = subdirectory_path.rsplit('_', 1)[-1] # Extract label from the subdirectory name
|
217 |
+
for file in os.listdir(subdirectory_path):
|
218 |
+
if any(file.endswith(f) for f in acceptable_formats):
|
219 |
+
file_path = os.path.join(subdirectory_path, file)
|
220 |
+
with open(file_path, 'rb') as file_handle:
|
221 |
+
ex = {"image": {"path": file_path, "bytes": file_handle.read()}, "label": label}
|
222 |
+
yield idx, ex
|
223 |
+
idx += 1
|