Update ecoset.py
Browse files
ecoset.py
CHANGED
@@ -118,7 +118,7 @@ class Ecoset(datasets.GeneratorBasedBuilder):
|
|
118 |
|
119 |
def abslist(path):
|
120 |
"""Helper function to give abspaths of os.listdir"""
|
121 |
-
return [
|
122 |
|
123 |
def subprocess_call_print(command_list):
|
124 |
"""Execute a subprocess while printing the command line output"""
|
@@ -151,18 +151,18 @@ class Ecoset(datasets.GeneratorBasedBuilder):
|
|
151 |
zip_file_path = os.path.join(target_dir, filename)
|
152 |
|
153 |
# Use subprocess to execute the modified wget command.
|
154 |
-
wget_command = f"wget --no-check-certificate {source_url} -O {zip_file_path}"
|
155 |
-
subprocess.run(wget_command, shell=True)
|
156 |
|
157 |
|
158 |
print(f"Downloaded {filename}")
|
159 |
# unzip using platform-based subprocess
|
160 |
-
if platform.system() in ("Linux", "Darwin"):
|
161 |
-
|
162 |
-
subprocess_call_print(["unzip", "-n", "-P", password.encode("ascii"), "-o", zip_file_path, "-d", target_dir])
|
163 |
-
else:
|
164 |
-
|
165 |
-
subprocess_call_print(["tar.exe", "-xf", zip_file_path, "-C", target_dir, "--passphrase", password])
|
166 |
|
167 |
|
168 |
|
@@ -174,10 +174,12 @@ class Ecoset(datasets.GeneratorBasedBuilder):
|
|
174 |
# create a dict containing all files
|
175 |
split_dict = {split:[] for split in ("train", "val", "test")}
|
176 |
for split in split_dict.keys():
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
181 |
# return data splits
|
182 |
return [datasets.SplitGenerator(
|
183 |
name=datasets.Split.TRAIN,
|
@@ -206,13 +208,19 @@ class Ecoset(datasets.GeneratorBasedBuilder):
|
|
206 |
def _generate_examples(self, archives, split):
|
207 |
"""Yields examples."""
|
208 |
idx = 0
|
209 |
-
|
210 |
-
|
211 |
-
|
|
|
|
|
|
|
|
|
212 |
# extract file, label, etc
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
|
|
|
|
|
118 |
|
119 |
def abslist(path):
|
120 |
"""Helper function to give abspaths of os.listdir"""
|
121 |
+
return [os.path.join(path, p) for p in os.listdir(path)if os.path.isdir(os.path.join(path, p))]
|
122 |
|
123 |
def subprocess_call_print(command_list):
|
124 |
"""Execute a subprocess while printing the command line output"""
|
|
|
151 |
zip_file_path = os.path.join(target_dir, filename)
|
152 |
|
153 |
# Use subprocess to execute the modified wget command.
|
154 |
+
#wget_command = f"wget --no-check-certificate {source_url} -O {zip_file_path}"
|
155 |
+
#subprocess.run(wget_command, shell=True)
|
156 |
|
157 |
|
158 |
print(f"Downloaded {filename}")
|
159 |
# unzip using platform-based subprocess
|
160 |
+
#if platform.system() in ("Linux", "Darwin"):
|
161 |
+
|
162 |
+
#subprocess_call_print(["unzip", "-n", "-P", password.encode("ascii"), "-o", zip_file_path, "-d", target_dir])
|
163 |
+
#else:
|
164 |
+
|
165 |
+
#subprocess_call_print(["tar.exe", "-xf", zip_file_path, "-C", target_dir, "--passphrase", password])
|
166 |
|
167 |
|
168 |
|
|
|
174 |
# create a dict containing all files
|
175 |
split_dict = {split:[] for split in ("train", "val", "test")}
|
176 |
for split in split_dict.keys():
|
177 |
+
# Get a list of file names in the current split's directory
|
178 |
+
fnames = abslist(os.path.join(archives, split))
|
179 |
+
|
180 |
+
# Extend the corresponding split's list in split_dict with the file names
|
181 |
+
split_dict[split].extend(fnames)
|
182 |
+
|
183 |
# return data splits
|
184 |
return [datasets.SplitGenerator(
|
185 |
name=datasets.Split.TRAIN,
|
|
|
208 |
def _generate_examples(self, archives, split):
|
209 |
"""Yields examples."""
|
210 |
idx = 0
|
211 |
+
split_archives = os.path.join(archives, split)
|
212 |
+
print(split_archives)
|
213 |
+
acceptable_formats = [".JPEG", ".JPG", ".jpeg", ".jpg"]
|
214 |
+
for archive in os.listdir(split_archives):
|
215 |
+
print(archive)
|
216 |
+
if any(archive.endswith(f) for f in acceptable_formats):
|
217 |
+
print('in')
|
218 |
# extract file, label, etc
|
219 |
+
file_path = os.path.join(split_archives, archive)
|
220 |
+
with open(file_path, 'rb') as file:
|
221 |
+
synset_id, label = archive.rsplit(os.path.sep, 2)[-2].split("_")
|
222 |
+
|
223 |
+
ex = {"image": {"path": archive, "bytes": file.read()}, "label": label}
|
224 |
+
print(ex)
|
225 |
+
yield idx, ex
|
226 |
+
idx += 1
|