vkapoor commited on
Commit
5f65f4b
·
1 Parent(s): 01063a1

Update ecoset.py

Browse files
Files changed (1) hide show
  1. ecoset.py +15 -13
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
- split_archives = os.path.join(archives, split)
209
- acceptable_formats = [".JPEG", ".JPG", ".jpeg", ".jpg"]
 
 
210
 
211
- subdirectories = [d for d in os.listdir(os.path.join(archives, split)) if os.path.isdir(os.path.join(archives, split, d))]
212
-
213
- for idx, subdirectory in enumerate(subdirectories):
214
- subdirectory_path = os.path.join(split_archives, subdirectory)
215
-
216
- for file in os.listdir(subdirectory_path):
217
- if any(file.endswith(f) for f in acceptable_formats):
218
- file_path = os.path.join(subdirectory_path, file)
219
- with open(file_path, 'rb') as file_handle:
220
- ex = {"image": {"path": file_path, "bytes": file_handle.read()}, "label": subdirectory_path.rsplit('_', 1)[-1]}
221
- yield idx, ex
 
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