vkapoor commited on
Commit
73a3818
·
1 Parent(s): 91504c5

Update ecoset.py

Browse files
Files changed (1) hide show
  1. ecoset.py +11 -11
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.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
 
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