Update audioset.py
Browse files- audioset.py +17 -14
audioset.py
CHANGED
@@ -73,6 +73,7 @@ class AudioSet(datasets.GeneratorBasedBuilder):
|
|
73 |
name="balanced",
|
74 |
description="",
|
75 |
),
|
|
|
76 |
AudioSetConfig(
|
77 |
features=datasets.Features(
|
78 |
{
|
@@ -82,9 +83,9 @@ class AudioSet(datasets.GeneratorBasedBuilder):
|
|
82 |
"label": datasets.Sequence(datasets.features.ClassLabel(names=CLASSES)),
|
83 |
}
|
84 |
),
|
85 |
-
name="unbalanced-
|
86 |
description="",
|
87 |
-
)
|
88 |
]
|
89 |
|
90 |
DEFAULT_CONFIG_NAME = "balanced"
|
@@ -116,9 +117,10 @@ class AudioSet(datasets.GeneratorBasedBuilder):
|
|
116 |
)
|
117 |
logger.info(f"`{_BALANCED_TRAIN_FILENAME}` is downloaded to {train_archive_path}")
|
118 |
|
119 |
-
elif self.config.name
|
|
|
120 |
for zip_type in ['zip', 'z01', 'z02']:
|
121 |
-
_UNBALANCED_TRAIN_FILENAME = f'
|
122 |
zip_file_url = f'https://huggingface.co/datasets/confit/audioset/resolve/main/unbalanced/{_UNBALANCED_TRAIN_FILENAME}'
|
123 |
_save_path = os.path.join(
|
124 |
HF_DATASETS_CACHE, 'confit___audioset/unbalanced', VERSION, _UNBALANCED_TRAIN_FILENAME
|
@@ -126,20 +128,21 @@ class AudioSet(datasets.GeneratorBasedBuilder):
|
|
126 |
download_file(zip_file_url, _save_path)
|
127 |
logger.info(f"`{_UNBALANCED_TRAIN_FILENAME}` is downloaded to {_save_path}")
|
128 |
|
129 |
-
main_zip_filename = '
|
130 |
-
concat_zip_filename = '
|
131 |
_input_file = os.path.join(HF_DATASETS_CACHE, 'confit___audioset/unbalanced', VERSION, main_zip_filename)
|
132 |
_output_file = os.path.join(HF_DATASETS_CACHE, 'confit___audioset/unbalanced', VERSION, concat_zip_filename)
|
133 |
|
134 |
if not os.path.exists(_output_file):
|
135 |
logger.info(f"Reassemble {_output_file} file")
|
136 |
os.system(f"zip -q -F {_input_file} --out {_output_file}")
|
|
|
|
|
|
|
|
|
137 |
train_archive_path = dl_manager.extract(_output_file)
|
138 |
logger.info(f"`{concat_zip_filename}` is downloaded to {train_archive_path}")
|
139 |
-
|
140 |
-
HF_DATASETS_CACHE, 'confit___audioset/unbalanced', VERSION, f'unbalanced_train_segments_part00_partial.*'
|
141 |
-
)
|
142 |
-
os.system(f"rm -rf {part_zip_files}")
|
143 |
|
144 |
zip_file_url = f'https://huggingface.co/datasets/confit/audioset/resolve/main/{_EVAL_FILENAME}'
|
145 |
_save_path = os.path.join(
|
@@ -164,7 +167,7 @@ class AudioSet(datasets.GeneratorBasedBuilder):
|
|
164 |
if split == 'train':
|
165 |
if self.config.name == 'balanced':
|
166 |
train_metadata_csv = f"{_HOMEPAGE}/resolve/main/metadata/balanced_train_segments.csv"
|
167 |
-
elif self.config.name
|
168 |
train_metadata_csv = f"{_HOMEPAGE}/resolve/main/metadata/unbalanced_train_segments.csv"
|
169 |
metadata_df = self._preprocess_metadata_csv(train_metadata_csv) # ['filename', 'ids']
|
170 |
elif split == 'test':
|
@@ -276,7 +279,7 @@ def download_file(
|
|
276 |
elif not os.path.isfile(dest) or (
|
277 |
os.path.isfile(dest) and replace_existing
|
278 |
):
|
279 |
-
|
280 |
with DownloadProgressBar(
|
281 |
unit="B",
|
282 |
unit_scale=True,
|
@@ -287,13 +290,13 @@ def download_file(
|
|
287 |
source, filename=dest, reporthook=t.update_to
|
288 |
)
|
289 |
else:
|
290 |
-
|
291 |
|
292 |
# Unpack if necessary
|
293 |
if unpack:
|
294 |
if dest_unpack is None:
|
295 |
dest_unpack = os.path.dirname(dest)
|
296 |
-
|
297 |
# shutil unpack_archive does not work with tar.gz files
|
298 |
if (
|
299 |
source.endswith(".tar.gz")
|
|
|
73 |
name="balanced",
|
74 |
description="",
|
75 |
),
|
76 |
+
] + [
|
77 |
AudioSetConfig(
|
78 |
features=datasets.Features(
|
79 |
{
|
|
|
83 |
"label": datasets.Sequence(datasets.features.ClassLabel(names=CLASSES)),
|
84 |
}
|
85 |
),
|
86 |
+
name=f"unbalanced-part{i:02d}",
|
87 |
description="",
|
88 |
+
) for i in range(40+1)
|
89 |
]
|
90 |
|
91 |
DEFAULT_CONFIG_NAME = "balanced"
|
|
|
117 |
)
|
118 |
logger.info(f"`{_BALANCED_TRAIN_FILENAME}` is downloaded to {train_archive_path}")
|
119 |
|
120 |
+
elif str(self.config.name).startswith('unbalanced-part'):
|
121 |
+
partxx = str(self.config.name).split('-')
|
122 |
for zip_type in ['zip', 'z01', 'z02']:
|
123 |
+
_UNBALANCED_TRAIN_FILENAME = f'unbalanced_train_segments_{partxx}_partial.{zip_type}'
|
124 |
zip_file_url = f'https://huggingface.co/datasets/confit/audioset/resolve/main/unbalanced/{_UNBALANCED_TRAIN_FILENAME}'
|
125 |
_save_path = os.path.join(
|
126 |
HF_DATASETS_CACHE, 'confit___audioset/unbalanced', VERSION, _UNBALANCED_TRAIN_FILENAME
|
|
|
128 |
download_file(zip_file_url, _save_path)
|
129 |
logger.info(f"`{_UNBALANCED_TRAIN_FILENAME}` is downloaded to {_save_path}")
|
130 |
|
131 |
+
main_zip_filename = f'unbalanced_train_segments_{partxx}_partial.zip'
|
132 |
+
concat_zip_filename = f'unbalanced_train_segments_{partxx}_full.zip'
|
133 |
_input_file = os.path.join(HF_DATASETS_CACHE, 'confit___audioset/unbalanced', VERSION, main_zip_filename)
|
134 |
_output_file = os.path.join(HF_DATASETS_CACHE, 'confit___audioset/unbalanced', VERSION, concat_zip_filename)
|
135 |
|
136 |
if not os.path.exists(_output_file):
|
137 |
logger.info(f"Reassemble {_output_file} file")
|
138 |
os.system(f"zip -q -F {_input_file} --out {_output_file}")
|
139 |
+
part_zip_files = os.path.join(
|
140 |
+
HF_DATASETS_CACHE, 'confit___audioset/unbalanced', VERSION, f'unbalanced_train_segments_{partxx}_partial.*'
|
141 |
+
)
|
142 |
+
os.system(f"rm -rf {part_zip_files}")
|
143 |
train_archive_path = dl_manager.extract(_output_file)
|
144 |
logger.info(f"`{concat_zip_filename}` is downloaded to {train_archive_path}")
|
145 |
+
|
|
|
|
|
|
|
146 |
|
147 |
zip_file_url = f'https://huggingface.co/datasets/confit/audioset/resolve/main/{_EVAL_FILENAME}'
|
148 |
_save_path = os.path.join(
|
|
|
167 |
if split == 'train':
|
168 |
if self.config.name == 'balanced':
|
169 |
train_metadata_csv = f"{_HOMEPAGE}/resolve/main/metadata/balanced_train_segments.csv"
|
170 |
+
elif str(self.config.name).startswith('unbalanced-part'):
|
171 |
train_metadata_csv = f"{_HOMEPAGE}/resolve/main/metadata/unbalanced_train_segments.csv"
|
172 |
metadata_df = self._preprocess_metadata_csv(train_metadata_csv) # ['filename', 'ids']
|
173 |
elif split == 'test':
|
|
|
279 |
elif not os.path.isfile(dest) or (
|
280 |
os.path.isfile(dest) and replace_existing
|
281 |
):
|
282 |
+
logger.info(f"Downloading {source} to {dest}")
|
283 |
with DownloadProgressBar(
|
284 |
unit="B",
|
285 |
unit_scale=True,
|
|
|
290 |
source, filename=dest, reporthook=t.update_to
|
291 |
)
|
292 |
else:
|
293 |
+
logger.info(f"{dest} exists. Skipping download")
|
294 |
|
295 |
# Unpack if necessary
|
296 |
if unpack:
|
297 |
if dest_unpack is None:
|
298 |
dest_unpack = os.path.dirname(dest)
|
299 |
+
logger.info(f"Extracting {dest} to {dest_unpack}")
|
300 |
# shutil unpack_archive does not work with tar.gz files
|
301 |
if (
|
302 |
source.endswith(".tar.gz")
|