Datasets:
File size: 20,896 Bytes
0525b47 09e5f0d 0525b47 10b5b90 0525b47 09e5f0d 0525b47 e1b1981 0525b47 0047e52 0525b47 a4c25dd 0525b47 0d75437 0525b47 59c8817 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 e1b1981 0525b47 ffe090a 0525b47 ffe090a 0525b47 ffe090a 0525b47 ffe090a 0525b47 ffe090a 0525b47 ffe090a 0525b47 ffe090a 0525b47 ffe090a 10b5b90 ffe090a 0525b47 0348e45 2a0e675 0348e45 0525b47 ffe090a 0525b47 53f5cf5 0525b47 53f5cf5 0525b47 5642776 ffe090a 0525b47 5642776 ffe090a 5642776 0525b47 53f5cf5 0525b47 8b262c0 0525b47 5642776 0525b47 8e4f142 0525b47 a5ed11f 0525b47 ffe090a 0525b47 a5ed11f 53f5cf5 0525b47 ffe090a 0525b47 ecd1566 0525b47 ffe090a 5837fb3 0525b47 59c8817 0525b47 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO: Address all TODOs and remove all explanatory comments
"""BirdSet: The General Avian Monitoring Evaluation Benchmark"""
import os
import datasets
import pandas as pd
from .classes import BIRD_NAMES_NIPS4BPLUS, BIRD_NAMES_AMAZON_BASIN, BIRD_NAMES_HAWAII, \
BIRD_NAMES_HIGH_SIERRAS, BIRD_NAMES_SIERRA_NEVADA, BIRD_NAMES_POWDERMILL_NATURE, BIRD_NAMES_SAPSUCKER, \
BIRD_NAMES_COLUMBIA_COSTA_RICA, BIRD_NAMES_XENOCANTO, BIRD_NAMES_XENOCANTO_M
from .descriptions import _BIRD_DB_CITATION, _NIPS4BPLUS_CITATION, _NIPS4BPLUS_DESCRIPTION, \
_HIGH_SIERRAS_DESCRIPTION, _HIGH_SIERRAS_CITATION, _SIERRA_NEVADA_DESCRIPTION, _SIERRA_NEVADA_CITATION, \
_POWDERMILL_NATURE_DESCRIPTION, _POWDERMILL_NATURE_CITATION, _AMAZON_BASIN_DESCRIPTION, _AMAZON_BASIN_CITATION, \
_SAPSUCKER_WOODS_DESCRIPTION, _SAPSUCKER_WOODS_CITATION, _COLUMBIA_COSTA_RICA_CITATION, \
_COLUMBIA_COSTA_RICA_DESCRIPTION, _HAWAIIAN_ISLANDS_CITATION, _HAWAIIAN_ISLANDS_DESCRIPTION
#############################################
_BIRDSET_CITATION = """\
@article{rauch2024,
title = {BirdSet: A Multi-Task Benchmark For Avian Diversity Monitoring},
author={Rauch, Lukas and Schwinger, Raphael and Wirth, Moritz and Lange, Jonas and Heinrich, René},
year={2024}
}
"""
_BIRDSET_DESCRIPTION = """\
This dataset offers a unified, well-structured platform for avian bioacoustics and consists of various tasks. \
By creating a set of tasks, BirdSet enables an overall performance score for models and uncovers their limitations \
in certain areas.
Note that each BirdSet dataset has its own citation. Please see the source to get the correct citation for each
contained dataset.
"""
base_url = "https://huggingface.co/datasets/DBD-research-group/gadme/resolve/data"
class BirdSetConfig(datasets.BuilderConfig):
def __init__(
self,
name,
citation,
class_list,
**kwargs):
super().__init__(version=datasets.Version("0.0.2"), name=name, **kwargs)
features = datasets.Features({
"audio": datasets.Audio(sampling_rate=32_000, mono=True, decode=False),
"filepath": datasets.Value("string"),
"start_time": datasets.Value("float64"), # can be changed to timestamp later
"end_time": datasets.Value("float64"),
"low_freq": datasets.Value("int64"),
"high_freq": datasets.Value("int64"),
"ebird_code": datasets.ClassLabel(names=class_list),
"ebird_code_multilabel": datasets.Sequence(datasets.ClassLabel(names=class_list)),
"ebird_code_secondary": datasets.Sequence(datasets.Value("string")),
"call_type": datasets.Value("string"),
"sex": datasets.Value("string"),
"lat": datasets.Value("float64"),
"long": datasets.Value("float64"),
"length": datasets.Value("int64"),
"microphone": datasets.Value("string"),
"license": datasets.Value("string"),
"source": datasets.Value("string"),
"local_time": datasets.Value("string"),
"detected_events": datasets.Sequence(datasets.Sequence(datasets.Value("float64"))),
"event_cluster": datasets.Sequence(datasets.Value("int64")),
"peaks": datasets.Sequence(datasets.Value("float64")),
"quality": datasets.Value("string"),
"recordist": datasets.Value("string"),
})
self.features = features
self.citation = citation
class BirdSet(datasets.GeneratorBasedBuilder):
"""TODO: Short description of my dataset."""
# ram problems?
DEFAULT_WRITER_BATCH_SIZE = 500
BUILDER_CONFIGS = [
BirdSetConfig(
name="SSW",
description=_SAPSUCKER_WOODS_DESCRIPTION,
citation=_SAPSUCKER_WOODS_CITATION,
data_dir=f"{base_url}/SSW",
class_list=BIRD_NAMES_SAPSUCKER,
),
BirdSetConfig(
name="SSW_xc",
description=_SAPSUCKER_WOODS_DESCRIPTION,
citation=_SAPSUCKER_WOODS_CITATION,
data_dir=f"{base_url}/SSW",
class_list=BIRD_NAMES_SAPSUCKER,
),
BirdSetConfig(
name="SSW_scape",
description=_SAPSUCKER_WOODS_DESCRIPTION,
citation=_SAPSUCKER_WOODS_CITATION,
data_dir=f"{base_url}/SSW",
class_list=BIRD_NAMES_SAPSUCKER,
),
BirdSetConfig(
name="PER",
description=_AMAZON_BASIN_DESCRIPTION,
citation=_AMAZON_BASIN_CITATION,
data_dir=f"{base_url}/PER",
class_list=BIRD_NAMES_AMAZON_BASIN,
),
BirdSetConfig(
name="PER_xc",
description=_AMAZON_BASIN_DESCRIPTION,
citation=_AMAZON_BASIN_CITATION,
data_dir=f"{base_url}/PER",
class_list=BIRD_NAMES_AMAZON_BASIN,
),
BirdSetConfig(
name="PER_scape",
description=_AMAZON_BASIN_DESCRIPTION,
citation=_AMAZON_BASIN_CITATION,
data_dir=f"{base_url}/PER",
class_list=BIRD_NAMES_AMAZON_BASIN,
),
BirdSetConfig(
name="UHH",
description=_HAWAIIAN_ISLANDS_DESCRIPTION,
citation=_HAWAIIAN_ISLANDS_CITATION,
data_dir=f"{base_url}/UHH",
class_list=BIRD_NAMES_HAWAII,
),
BirdSetConfig(
name="UHH_xc",
description=_HAWAIIAN_ISLANDS_DESCRIPTION,
citation=_HAWAIIAN_ISLANDS_CITATION,
data_dir=f"{base_url}/UHH",
class_list=BIRD_NAMES_HAWAII,
),
BirdSetConfig(
name="UHH_scape",
description=_HAWAIIAN_ISLANDS_DESCRIPTION,
citation=_HAWAIIAN_ISLANDS_CITATION,
data_dir=f"{base_url}/UHH",
class_list=BIRD_NAMES_HAWAII,
),
BirdSetConfig(
name="SNE",
description=_SIERRA_NEVADA_DESCRIPTION,
citation=_SIERRA_NEVADA_CITATION,
data_dir=f"{base_url}/SNE",
class_list=BIRD_NAMES_SIERRA_NEVADA,
),
BirdSetConfig(
name="SNE_xc",
description=_SIERRA_NEVADA_DESCRIPTION,
citation=_SIERRA_NEVADA_CITATION,
data_dir=f"{base_url}/SNE",
class_list=BIRD_NAMES_SIERRA_NEVADA,
),
BirdSetConfig(
name="SNE_scape",
description=_SIERRA_NEVADA_DESCRIPTION,
citation=_SIERRA_NEVADA_CITATION,
data_dir=f"{base_url}/SNE",
class_list=BIRD_NAMES_SIERRA_NEVADA,
),
BirdSetConfig(
name="POW",
description=_POWDERMILL_NATURE_DESCRIPTION,
citation=_POWDERMILL_NATURE_CITATION,
data_dir=f"{base_url}/POW",
class_list=BIRD_NAMES_POWDERMILL_NATURE,
),
BirdSetConfig(
name="POW_xc",
description=_POWDERMILL_NATURE_DESCRIPTION,
citation=_POWDERMILL_NATURE_CITATION,
data_dir=f"{base_url}/POW",
class_list=BIRD_NAMES_POWDERMILL_NATURE,
),
BirdSetConfig(
name="POW_scape",
description=_POWDERMILL_NATURE_DESCRIPTION,
citation=_POWDERMILL_NATURE_CITATION,
data_dir=f"{base_url}/POW",
class_list=BIRD_NAMES_POWDERMILL_NATURE,
),
BirdSetConfig(
name="HSN",
description=_HIGH_SIERRAS_DESCRIPTION,
citation=_HIGH_SIERRAS_CITATION,
data_dir=f"{base_url}/HSN",
class_list=BIRD_NAMES_HIGH_SIERRAS,
),
BirdSetConfig(
name="HSN_xc",
description=_HIGH_SIERRAS_DESCRIPTION,
citation=_HIGH_SIERRAS_CITATION,
data_dir=f"{base_url}/HSN",
class_list=BIRD_NAMES_HIGH_SIERRAS,
),
BirdSetConfig(
name="HSN_scape",
description=_HIGH_SIERRAS_DESCRIPTION,
citation=_HIGH_SIERRAS_CITATION,
data_dir=f"{base_url}/HSN",
class_list=BIRD_NAMES_HIGH_SIERRAS,
),
BirdSetConfig(
name="NES",
description=_COLUMBIA_COSTA_RICA_DESCRIPTION,
citation=_COLUMBIA_COSTA_RICA_CITATION,
data_dir=f"{base_url}/NES",
class_list=BIRD_NAMES_COLUMBIA_COSTA_RICA,
),
BirdSetConfig(
name="NES_xc",
description=_COLUMBIA_COSTA_RICA_DESCRIPTION,
citation=_COLUMBIA_COSTA_RICA_CITATION,
data_dir=f"{base_url}/NES",
class_list=BIRD_NAMES_COLUMBIA_COSTA_RICA,
),
BirdSetConfig(
name="NES_scape",
description=_COLUMBIA_COSTA_RICA_DESCRIPTION,
citation=_COLUMBIA_COSTA_RICA_CITATION,
data_dir=f"{base_url}/NES",
class_list=BIRD_NAMES_COLUMBIA_COSTA_RICA,
),
BirdSetConfig(
name="NBP",
description=_NIPS4BPLUS_DESCRIPTION,
citation=_NIPS4BPLUS_CITATION,
data_dir=f"{base_url}/NBP",
class_list=BIRD_NAMES_NIPS4BPLUS,
),
BirdSetConfig(
name="NBP_xc",
description=_NIPS4BPLUS_DESCRIPTION,
citation=_NIPS4BPLUS_CITATION,
data_dir=f"{base_url}/NBP",
class_list=BIRD_NAMES_NIPS4BPLUS,
),
BirdSetConfig(
name="NBP_scape",
description=_NIPS4BPLUS_DESCRIPTION,
citation=_NIPS4BPLUS_CITATION,
data_dir=f"{base_url}/NBP",
class_list=BIRD_NAMES_NIPS4BPLUS,
),
BirdSetConfig(
name="XCM",
description="TODO",
citation="TODO",
data_dir=f"{base_url}/XCM",
class_list=BIRD_NAMES_XENOCANTO_M,
),
BirdSetConfig(
name="XCL",
description="TODO",
citation="TODO",
data_dir=f"{base_url}/XCL",
class_list=BIRD_NAMES_XENOCANTO,
),
]
def _info(self):
return datasets.DatasetInfo(
description=_BIRDSET_DESCRIPTION + self.config.description,
features=self.config.features,
citation=self.config.citation + "\n" + _BIRDSET_CITATION,
)
def _split_generators(self, dl_manager):
ds_name = self.config.name
train_files = {"PER": 11,
"NES": 13,
"UHH": 5,
"HSN": 7,
"NBP": 32,
"POW": 9,
"SSW": 29,
"SNE": 21,
"XCM": 182,
"XCL": 98}
test_files = {"PER": 3,
"NES": 8,
"UHH": 7,
"HSN": 3,
"NBP": 1,
"POW": 3,
"SSW": 36,
"SNE": 5}
test5s_files = {"PER": 1,
"NES": 1,
"UHH": 1,
"HSN": 1,
"NBP": 1,
"POW": 1,
"SSW": 4,
"SNE": 1}
if self.config.name.endswith("_xc"):
ds_name = ds_name[:-3]
dl_dir = dl_manager.download({
"train": [os.path.join(self.config.data_dir, f"{ds_name}_train_shard_{n:04d}.tar.gz") for n in range(1, train_files[ds_name] + 1)],
"metadata": os.path.join(self.config.data_dir, f"{ds_name}_metadata_train.parquet"),
})
elif self.config.name.endswith("_scape"):
ds_name = ds_name[:-6]
dl_dir = dl_manager.download({
"test": [os.path.join(self.config.data_dir, f"{ds_name}_test_shard_{n:04d}.tar.gz") for n in range(1, test_files[ds_name] + 1)],
"test_5s": [os.path.join(self.config.data_dir, f"{ds_name}_test5s_shard_{n:04d}.tar.gz") for n in range(1, test5s_files[ds_name] + 1)],
"metadata": os.path.join(self.config.data_dir, f"{ds_name}_metadata_test.parquet"),
"metadata_5s": os.path.join(self.config.data_dir, f"{ds_name}_metadata_test_5s.parquet"),
})
# use POW for XCM/XCL validation
elif self.config.name.startswith("XC"):
dl_dir = dl_manager.download({
"train": [os.path.join(self.config.data_dir, f"{ds_name}_shard_{n:04d}.tar.gz") for n in range(1, train_files[ds_name] + 1)],
"valid": [os.path.join(self.config.data_dir.replace("XCM", "POW"), f"POW_test5s_shard_{n:04d}.tar.gz") for n in range(1, test5s_files["POW"] + 1)],
"metadata": os.path.join(self.config.data_dir, f"{ds_name}_metadata.parquet"),
"meta_test_5s": os.path.join(self.config.data_dir.replace("XCM", "POW"), f"POW_metadata_test_5s.parquet"),
})
elif self.config.name in train_files.keys():
dl_dir = dl_manager.download({
"train": [os.path.join(self.config.data_dir, f"{ds_name}_train_shard_{n:04d}.tar.gz") for n in range(1, train_files[ds_name] + 1)],
"test": [os.path.join(self.config.data_dir, f"{ds_name}_test_shard_{n:04d}.tar.gz") for n in range(1, test_files[ds_name] + 1)],
"test_5s": [os.path.join(self.config.data_dir, f"{ds_name}_test5s_shard_{n:04d}.tar.gz") for n in range(1, test5s_files[ds_name] + 1)],
"meta_train": os.path.join(self.config.data_dir, f"{ds_name}_metadata_train.parquet"),
"meta_test": os.path.join(self.config.data_dir, f"{ds_name}_metadata_test.parquet"),
"meta_test_5s": os.path.join(self.config.data_dir, f"{ds_name}_metadata_test_5s.parquet"),
})
local_audio_archives_paths = dl_manager.extract(dl_dir) if not dl_manager.is_streaming else None
if self.config.name.startswith("XC") or self.config.name.endswith("_xc"):
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"audio_archive_iterators": [dl_manager.iter_archive(archive_path) for archive_path in dl_dir["train"]],
"local_audio_archives_paths": local_audio_archives_paths["train"] if local_audio_archives_paths else None,
"metapath": dl_dir["metadata"],
"split": datasets.Split.TRAIN,
},
),
datasets.SplitGenerator(
name="valid",
gen_kwargs={
"audio_archive_iterators": [dl_manager.iter_archive(archive_path) for archive_path in dl_dir["valid"]],
"local_audio_archives_paths": local_audio_archives_paths["valid"] if local_audio_archives_paths else None,
"metapath": dl_dir["meta_test_5s"],
"split": "valid",
},
),
]
elif self.config.name.endswith("_scape"):
return [
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"audio_archive_iterators": [dl_manager.iter_archive(archive_path) for archive_path in dl_dir["test"]],
"local_audio_archives_paths": local_audio_archives_paths["test"] if local_audio_archives_paths else None,
"metapath": dl_dir["metadata"],
"split": datasets.Split.TEST,
},
),
datasets.SplitGenerator(
name="test_5s",
gen_kwargs={
"audio_archive_iterators": [dl_manager.iter_archive(archive_path) for archive_path in dl_dir["test_5s"]],
"local_audio_archives_paths": local_audio_archives_paths["test_5s"] if local_audio_archives_paths else None,
"metapath": dl_dir["metadata_5s"],
"split": "test_multilabel"
},
),
]
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"audio_archive_iterators": [dl_manager.iter_archive(archive_path) for archive_path in dl_dir["train"]],
"local_audio_archives_paths": local_audio_archives_paths["train"] if local_audio_archives_paths else None,
"metapath": dl_dir["meta_train"],
"split": datasets.Split.TRAIN,
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"audio_archive_iterators": [dl_manager.iter_archive(archive_path) for archive_path in dl_dir["test"]],
"local_audio_archives_paths": local_audio_archives_paths["test"] if local_audio_archives_paths else None,
"metapath": dl_dir["meta_test"],
"split": datasets.Split.TEST,
},
),
datasets.SplitGenerator(
name="test_5s",
gen_kwargs={
"audio_archive_iterators": [dl_manager.iter_archive(archive_path) for archive_path in dl_dir["test_5s"]],
"local_audio_archives_paths": local_audio_archives_paths["test_5s"] if local_audio_archives_paths else None,
"metapath": dl_dir["meta_test_5s"],
"split": "test_multilabel"
},
),
]
def _generate_examples(self, audio_archive_iterators, local_audio_archives_paths, metapath, split):
metadata = pd.read_parquet(metapath)
idx = 0
for i, audio_archive_iterator in enumerate(audio_archive_iterators):
for audio_path_in_archive, audio_file in audio_archive_iterator:
id = os.path.split(audio_path_in_archive)[-1]
rows = metadata[metadata.index == (int(id[2:].split(".")[0]) if split == "train" else id)]
audio_path = os.path.join(local_audio_archives_paths[i], audio_path_in_archive) if local_audio_archives_paths else audio_path_in_archive
audio = audio_path if local_audio_archives_paths else audio_file.read()
for _, row in rows.iterrows():
idx += 1
yield id if split == "train" else idx, {
"audio": audio,
"filepath": audio_path,
"start_time": row["start_time"],
"end_time": row["end_time"],
"low_freq": row["low_freq"],
"high_freq": row["high_freq"],
"ebird_code": row["ebird_code"] if split != "test_multilabel" else None,
#"ebird_code_multilabel": row.get("ebird_code_multilabel", None),
"ebird_code_multilabel": row.get("ebird_code_multilabel", None) if "no_call" not in row.get("ebird_code_multilabel", []) else [],
"ebird_code_secondary": row.get("ebird_code_secondary", None),
"call_type": row["call_type"],
"sex": row["sex"],
"lat": row["lat"],
"long": row["long"],
"length": row.get("length", None),
"microphone": row["microphone"],
"license": row.get("license", None),
"source": row["source"],
"local_time": row["local_time"],
"detected_events": row.get("detected_events", None),
"event_cluster": row.get("event_cluster", None),
"peaks": row.get("peaks", None),
"quality": row.get("quality", None),
"recordist": row.get("recordist", None)
}
|