Update audioset.py
Browse files- audioset.py +26 -22
audioset.py
CHANGED
@@ -10,6 +10,7 @@ import joblib
|
|
10 |
import shutil
|
11 |
import pathlib
|
12 |
import logging
|
|
|
13 |
import textwrap
|
14 |
import datasets
|
15 |
import itertools
|
@@ -152,8 +153,11 @@ class AudioSet(datasets.GeneratorBasedBuilder):
|
|
152 |
HF_DATASETS_CACHE, 'confit___audioset/unbalanced', VERSION, f'unbalanced_train_segments_{partxx}_partial.*'
|
153 |
)
|
154 |
os.system(f"rm -rf {part_zip_files}")
|
155 |
-
|
156 |
-
train_archive_path =
|
|
|
|
|
|
|
157 |
logger.info(f"`{concat_zip_filename}` is extracted to {train_archive_path}")
|
158 |
|
159 |
zip_file_url = f'https://huggingface.co/datasets/confit/audioset/resolve/main/{_EVAL_FILENAME}'
|
@@ -339,26 +343,26 @@ def download_file(
|
|
339 |
set_writing_permissions(dest_unpack)
|
340 |
|
341 |
|
342 |
-
def
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
|
363 |
|
364 |
def set_writing_permissions(folder_path):
|
|
|
10 |
import shutil
|
11 |
import pathlib
|
12 |
import logging
|
13 |
+
import zipfile
|
14 |
import textwrap
|
15 |
import datasets
|
16 |
import itertools
|
|
|
153 |
HF_DATASETS_CACHE, 'confit___audioset/unbalanced', VERSION, f'unbalanced_train_segments_{partxx}_partial.*'
|
154 |
)
|
155 |
os.system(f"rm -rf {part_zip_files}")
|
156 |
+
|
157 |
+
train_archive_path = os.path.join(
|
158 |
+
HF_DATASETS_CACHE, 'confit___audioset/unbalanced', VERSION, 'extracted'
|
159 |
+
)
|
160 |
+
unzip_file(zip_path=_output_file, extract_to=train_archive_path)
|
161 |
logger.info(f"`{concat_zip_filename}` is extracted to {train_archive_path}")
|
162 |
|
163 |
zip_file_url = f'https://huggingface.co/datasets/confit/audioset/resolve/main/{_EVAL_FILENAME}'
|
|
|
343 |
set_writing_permissions(dest_unpack)
|
344 |
|
345 |
|
346 |
+
def unzip_file(zip_path, extract_to):
|
347 |
+
"""
|
348 |
+
Unzips a given zip file to a specified directory.
|
349 |
+
|
350 |
+
Parameters:
|
351 |
+
zip_path (str): The path to the zip file.
|
352 |
+
extract_to (str): The directory to extract the files to.
|
353 |
+
"""
|
354 |
+
if os.path.exists(extract_to):
|
355 |
+
logger.info(f"{extract_to} already exists. Skipping extraction")
|
356 |
+
|
357 |
+
if not os.path.exists(zip_path):
|
358 |
+
raise FileNotFoundError(f"The file {zip_path} does not exist.")
|
359 |
+
|
360 |
+
if not os.path.exists(extract_to):
|
361 |
+
os.makedirs(extract_to)
|
362 |
+
|
363 |
+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
364 |
+
zip_ref.extractall(extract_to)
|
365 |
+
logger.info(f"Extracted {zip_path} to {extract_to}")
|
366 |
|
367 |
|
368 |
def set_writing_permissions(folder_path):
|