vkapoor commited on
Commit
608f3c2
·
1 Parent(s): 3fae74d

Update ecoset.py

Browse files
Files changed (1) hide show
  1. ecoset.py +14 -14
ecoset.py CHANGED
@@ -212,18 +212,18 @@ class Ecoset(datasets.GeneratorBasedBuilder):
212
  """Yields examples."""
213
  idx = 0
214
  split_archives = os.path.join(archives, split)
215
-
216
  acceptable_formats = [".JPEG", ".JPG", ".jpeg", ".jpg"]
217
- for archive in os.listdir(split_archives):
218
-
219
- if any(archive.endswith(f) for f in acceptable_formats):
220
-
221
- # extract file, label, etc
222
- file_path = os.path.join(split_archives, archive)
223
- with open(file_path, 'rb') as file:
224
- synset_id, label = archive.rsplit(os.path.sep, 2)[-2].split("_")
225
-
226
- ex = {"image": {"path": archive, "bytes": file.read()}, "label": label}
227
-
228
- yield idx, ex
229
- idx += 1
 
 
212
  """Yields examples."""
213
  idx = 0
214
  split_archives = os.path.join(archives, split)
 
215
  acceptable_formats = [".JPEG", ".JPG", ".jpeg", ".jpg"]
216
+
217
+ for subdirectory in os.listdir(split_archives):
218
+ subdirectory_path = os.path.join(split_archives, subdirectory)
219
+ if os.path.isdir(subdirectory_path):
220
+ label = subdirectory # Assuming the folder name is the label
221
+
222
+ for file in os.listdir(subdirectory_path):
223
+ if any(file.endswith(f) for f in acceptable_formats):
224
+
225
+ file_path = os.path.join(subdirectory_path, file)
226
+ with open(file_path, 'rb') as file_handle:
227
+ ex = {"image": {"path": file_path, "bytes": file_handle.read()}, "label": label}
228
+ yield idx, ex
229
+ idx += 1