mwirth7 commited on
Commit
c316169
·
verified ·
1 Parent(s): 7675857

Update BirdSet.py

Browse files
Files changed (1) hide show
  1. BirdSet.py +27 -16
BirdSet.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
  #
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
  # you may not use this file except in compliance with the License.
@@ -11,13 +11,14 @@
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
  # See the License for the specific language governing permissions and
13
  # limitations under the License.
14
- """BirdSet: The General Avian Monitoring Evaluation Benchmark"""
15
 
16
  import os
17
  import datasets
18
  import pandas as pd
19
  from tqdm.auto import tqdm
20
  import tarfile
 
21
 
22
  from . import classes
23
 
@@ -34,18 +35,28 @@ from .descriptions import _NIPS4BPLUS_CITATION, _NIPS4BPLUS_DESCRIPTION, \
34
 
35
  #############################################
36
  _BIRDSET_CITATION = """\
37
- @article{birdset,
38
- title = {BirdSet: A Multi-Task Benchmark For Avian Diversity Monitoring},
39
- author={anonymous},
40
- year={2024}
 
 
 
 
41
  }
42
  """
43
  _BIRDSET_DESCRIPTION = """\
44
- This dataset offers a unified, well-structured platform for avian bioacoustics and consists of various tasks. \
45
- By creating a set of tasks, BirdSet enables an overall performance score for models and uncovers their limitations \
46
- in certain areas.
47
- Note that each BirdSet dataset has its own citation. Please see the source to get the correct citation for each
48
- contained dataset.
 
 
 
 
 
 
49
  """
50
 
51
  base_url = "https://huggingface.co/datasets/DBD-research-group/BirdSet/resolve/data"
@@ -67,7 +78,7 @@ def _extract_all_to_same_folder(tar_path, output_dir):
67
  return output_dir
68
 
69
 
70
- def _extract_and_delete(dl_dir: dict) -> dict:
71
  """extracts downloaded files and deletes the archive file immediately, with progress bar.
72
  only the processed archive and its content are saved at the same time."""
73
  audio_paths = {name: [] for name, data in dl_dir.items() if isinstance(data, list)}
@@ -77,8 +88,8 @@ def _extract_and_delete(dl_dir: dict) -> dict:
77
 
78
  # extract and immediately delete archives
79
  for path in tqdm(data, f"Extracting {name} split"):
80
- head, tail = os.path.split(path)
81
- output_dir = os.path.join(head, "extracted", tail)
82
  #audio_path = dl_manager.extract(path) # if all archive files are without subfolders this works just fine
83
  audio_path = _extract_all_to_same_folder(path, output_dir)
84
  os.remove(path)
@@ -105,7 +116,7 @@ class BirdSetConfig(datasets.BuilderConfig):
105
  features = datasets.Features({
106
  "audio": datasets.Audio(sampling_rate=32_000, mono=True, decode=False),
107
  "filepath": datasets.Value("string"),
108
- "start_time": datasets.Value("float64"), # can be changed to timestamp later
109
  "end_time": datasets.Value("float64"),
110
  "low_freq": datasets.Value("int64"),
111
  "high_freq": datasets.Value("int64"),
@@ -482,7 +493,7 @@ class BirdSet(datasets.GeneratorBasedBuilder):
482
  })
483
 
484
  # custom extraction that deletes archives right after extraction
485
- audio_paths = _extract_and_delete(dl_dir) if not dl_manager.is_streaming else None
486
 
487
  # construct split generators
488
  # assumes every key in dl_dir of NAME also has meta_NAME
 
1
+ # Copyright 2025 The HuggingFace Datasets Authors and the current dataset script contributor.
2
  #
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
  # you may not use this file except in compliance with the License.
 
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
  # See the License for the specific language governing permissions and
13
  # limitations under the License.
14
+ """BirdSet: A Large-Scale Dataset for Audio Classification in Avian Bioacoustics"""
15
 
16
  import os
17
  import datasets
18
  import pandas as pd
19
  from tqdm.auto import tqdm
20
  import tarfile
21
+ from pathlib import Path
22
 
23
  from . import classes
24
 
 
35
 
36
  #############################################
37
  _BIRDSET_CITATION = """\
38
+ @misc{rauch2025birdsetlargescaledatasetaudio,
39
+ title={BirdSet: A Large-Scale Dataset for Audio Classification in Avian Bioacoustics},
40
+ author={Lukas Rauch and Raphael Schwinger and Moritz Wirth and René Heinrich and Denis Huseljic and Marek Herde and Jonas Lange and Stefan Kahl and Bernhard Sick and Sven Tomforde and Christoph Scholz},
41
+ year={2025},
42
+ eprint={2403.10380},
43
+ archivePrefix={arXiv},
44
+ primaryClass={cs.SD},
45
+ url={https://arxiv.org/abs/2403.10380},
46
  }
47
  """
48
  _BIRDSET_DESCRIPTION = """\
49
+ Deep learning (DL) has greatly advanced audio classification,
50
+ yet the field is limited by the scarcity of large-scale benchmark datasets that have propelled progress in other domains.
51
+ While AudioSet is a pivotal step to bridge this gap as a universal-domain dataset, its restricted accessibility and
52
+ limited range of evaluation use cases challenge its role as the sole resource. Therefore, we introduce BirdSet,
53
+ a large-scale benchmark dataset for audio classification focusing on avian bioacoustics.
54
+ BirdSet surpasses AudioSet with over 6,800 recording hours (+17%) from nearly 10,000 classes (x18) for training and more
55
+ than 400 hours (x7) across eight strongly labeled evaluation datasets. It serves as a versatile resource for use
56
+ cases such as multi-label classification, covariate shift or self-supervised learning. We benchmark six well-known
57
+ DL models in multi-label classification across three distinct training scenarios and outline further evaluation use
58
+ cases in audio classification. We host our dataset on Hugging Face for easy accessibility and offer an extensive
59
+ codebase to reproduce our results.
60
  """
61
 
62
  base_url = "https://huggingface.co/datasets/DBD-research-group/BirdSet/resolve/data"
 
78
  return output_dir
79
 
80
 
81
+ def _extract_and_delete(dl_dir: dict, cache_dir: str = None) -> dict:
82
  """extracts downloaded files and deletes the archive file immediately, with progress bar.
83
  only the processed archive and its content are saved at the same time."""
84
  audio_paths = {name: [] for name, data in dl_dir.items() if isinstance(data, list)}
 
88
 
89
  # extract and immediately delete archives
90
  for path in tqdm(data, f"Extracting {name} split"):
91
+ directory, filename = os.path.split(path)
92
+ output_dir = os.path.join(cache_dir or directory, "extracted", filename.split(".")[0])
93
  #audio_path = dl_manager.extract(path) # if all archive files are without subfolders this works just fine
94
  audio_path = _extract_all_to_same_folder(path, output_dir)
95
  os.remove(path)
 
116
  features = datasets.Features({
117
  "audio": datasets.Audio(sampling_rate=32_000, mono=True, decode=False),
118
  "filepath": datasets.Value("string"),
119
+ "start_time": datasets.Value("float64"),
120
  "end_time": datasets.Value("float64"),
121
  "low_freq": datasets.Value("int64"),
122
  "high_freq": datasets.Value("int64"),
 
493
  })
494
 
495
  # custom extraction that deletes archives right after extraction
496
+ audio_paths = _extract_and_delete(dl_dir, dl_manager.download_config.cache_dir) if not dl_manager.is_streaming else None
497
 
498
  # construct split generators
499
  # assumes every key in dl_dir of NAME also has meta_NAME