Update ecoset.py
Browse files
ecoset.py
CHANGED
@@ -210,14 +210,14 @@ class Ecoset(datasets.GeneratorBasedBuilder):
|
|
210 |
split_archives = os.path.join(archives, split)
|
211 |
acceptable_formats = [".JPEG", ".JPG", ".jpeg", ".jpg"]
|
212 |
|
213 |
-
for subdirectory in os.
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
|
|
210 |
split_archives = os.path.join(archives, split)
|
211 |
acceptable_formats = [".JPEG", ".JPG", ".jpeg", ".jpg"]
|
212 |
|
213 |
+
for subdirectory, dirs, files in os.walk(split_archives):
|
214 |
+
label = subdirectory.rsplit('_', 1)[-1]
|
215 |
+
for file in files:
|
216 |
+
if any(file.endswith(f) for f in acceptable_formats):
|
217 |
+
file_path = os.path.join(subdirectory, file)
|
218 |
+
# Calculate the relative path from the base directory
|
219 |
+
rel_path = os.path.relpath(file_path, split_archives)
|
220 |
+
with open(file_path, 'rb') as file_handle:
|
221 |
+
ex = {"image": {"path": rel_path, "bytes": file_handle.read()}, "label": label}
|
222 |
+
yield idx, ex
|
223 |
+
idx += 1
|