Datasets:
Tasks:
Audio Classification
Modalities:
Audio
Languages:
English
Tags:
audio
music-classification
meter-classification
multi-class-classification
multi-label-classification
License:
Commit ·
de731d3
1
Parent(s): 747f6d0
Refactor Meter2800 dataset class by removing unused variables and simplifying example generation logic
Browse files- meter2800.py +11 -84
meter2800.py
CHANGED
|
@@ -1,115 +1,42 @@
|
|
| 1 |
import datasets
|
| 2 |
import pandas as pd
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
|
| 5 |
-
_CITATION = """\
|
| 6 |
-
@misc{meter2800_dataset,
|
| 7 |
-
author = {PianistProgrammer},
|
| 8 |
-
title = {{Meter2800}: A Dataset for Music Time signature detection / Meter Classification},
|
| 9 |
-
year = {2025},
|
| 10 |
-
publisher = {Hugging Face},
|
| 11 |
-
url = {https://huggingface.co/datasets/pianistprogrammer/Meter2800}
|
| 12 |
-
}
|
| 13 |
-
"""
|
| 14 |
-
|
| 15 |
-
_DESCRIPTION = """\
|
| 16 |
-
Meter2800 is a dataset of 2,800 music audio samples for automatic meter classification.
|
| 17 |
-
Each audio file is annotated with a primary meter class label and an alternative meter.
|
| 18 |
-
It is split into training, validation, and test sets, each available in two class configurations:
|
| 19 |
-
2-class and 4-class. All audio is 16-bit WAV format.
|
| 20 |
-
"""
|
| 21 |
-
|
| 22 |
-
_HOMEPAGE = "https://huggingface.co/datasets/pianistprogrammer/Meter2800"
|
| 23 |
-
_LICENSE = "mit"
|
| 24 |
|
| 25 |
class Meter2800(datasets.GeneratorBasedBuilder):
|
| 26 |
-
"""
|
| 27 |
|
| 28 |
-
VERSION = datasets.Version("1.0.0")
|
| 29 |
-
|
| 30 |
BUILDER_CONFIGS = [
|
| 31 |
-
datasets.BuilderConfig(
|
| 32 |
-
|
| 33 |
-
version=VERSION,
|
| 34 |
-
description="4-class meter classification",
|
| 35 |
-
),
|
| 36 |
-
datasets.BuilderConfig(
|
| 37 |
-
name="2_classes",
|
| 38 |
-
version=VERSION,
|
| 39 |
-
description="2-class meter classification",
|
| 40 |
-
),
|
| 41 |
]
|
| 42 |
-
|
| 43 |
DEFAULT_CONFIG_NAME = "4_classes"
|
| 44 |
|
| 45 |
def _info(self):
|
| 46 |
-
# We'll determine the labels dynamically from the CSV files
|
| 47 |
-
# For now, use a generic ClassLabel that will be updated later
|
| 48 |
return datasets.DatasetInfo(
|
| 49 |
-
description=_DESCRIPTION,
|
| 50 |
features=datasets.Features({
|
| 51 |
"filename": datasets.Value("string"),
|
| 52 |
"audio": datasets.Audio(sampling_rate=None),
|
| 53 |
-
"label": datasets.Value("string"),
|
| 54 |
"meter": datasets.Value("string"),
|
| 55 |
"alt_meter": datasets.Value("string"),
|
| 56 |
}),
|
| 57 |
-
supervised_keys=("audio", "label"),
|
| 58 |
-
homepage=_HOMEPAGE,
|
| 59 |
-
license=_LICENSE,
|
| 60 |
-
citation=_CITATION,
|
| 61 |
)
|
| 62 |
|
| 63 |
def _split_generators(self, dl_manager):
|
| 64 |
-
"""Returns SplitGenerators."""
|
| 65 |
-
|
| 66 |
-
# The files should be in the root of the repo
|
| 67 |
-
config_suffix = self.config.name
|
| 68 |
-
|
| 69 |
return [
|
| 70 |
datasets.SplitGenerator(
|
| 71 |
name=datasets.Split.TRAIN,
|
| 72 |
-
gen_kwargs={
|
| 73 |
-
"csv_file": f"data_train_{config_suffix}.csv",
|
| 74 |
-
"split": "train",
|
| 75 |
-
},
|
| 76 |
-
),
|
| 77 |
-
datasets.SplitGenerator(
|
| 78 |
-
name=datasets.Split.VALIDATION,
|
| 79 |
-
gen_kwargs={
|
| 80 |
-
"csv_file": f"data_val_{config_suffix}.csv",
|
| 81 |
-
"split": "validation",
|
| 82 |
-
},
|
| 83 |
-
),
|
| 84 |
-
datasets.SplitGenerator(
|
| 85 |
-
name=datasets.Split.TEST,
|
| 86 |
-
gen_kwargs={
|
| 87 |
-
"csv_file": f"data_test_{config_suffix}.csv",
|
| 88 |
-
"split": "test",
|
| 89 |
-
},
|
| 90 |
),
|
| 91 |
]
|
| 92 |
|
| 93 |
-
def _generate_examples(self, csv_file
|
| 94 |
-
"""Yields examples."""
|
| 95 |
-
|
| 96 |
-
# Read CSV directly - the file should be available in the repo
|
| 97 |
-
df = pd.read_csv(csv_file)
|
| 98 |
-
|
| 99 |
-
# Read CSV
|
| 100 |
df = pd.read_csv(csv_file)
|
| 101 |
-
df = df.dropna(subset=["filename", "label"]).reset_index(drop=True)
|
| 102 |
-
|
| 103 |
for idx, row in df.iterrows():
|
| 104 |
-
# The audio files should be in subdirectories
|
| 105 |
-
audio_file = row["filename"]
|
| 106 |
-
if not audio_file.startswith("/"):
|
| 107 |
-
audio_file = "/" + audio_file
|
| 108 |
-
|
| 109 |
yield idx, {
|
| 110 |
"filename": row["filename"],
|
| 111 |
-
"audio":
|
| 112 |
-
"label":
|
| 113 |
-
"meter": str(row
|
| 114 |
-
"alt_meter": str(row
|
| 115 |
}
|
|
|
|
| 1 |
import datasets
|
| 2 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
class Meter2800(datasets.GeneratorBasedBuilder):
|
| 5 |
+
"""Minimal test version."""
|
| 6 |
|
|
|
|
|
|
|
| 7 |
BUILDER_CONFIGS = [
|
| 8 |
+
datasets.BuilderConfig(name="4_classes", description="4 class version"),
|
| 9 |
+
datasets.BuilderConfig(name="2_classes", description="2 class version"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
]
|
| 11 |
+
|
| 12 |
DEFAULT_CONFIG_NAME = "4_classes"
|
| 13 |
|
| 14 |
def _info(self):
|
|
|
|
|
|
|
| 15 |
return datasets.DatasetInfo(
|
|
|
|
| 16 |
features=datasets.Features({
|
| 17 |
"filename": datasets.Value("string"),
|
| 18 |
"audio": datasets.Audio(sampling_rate=None),
|
| 19 |
+
"label": datasets.Value("string"),
|
| 20 |
"meter": datasets.Value("string"),
|
| 21 |
"alt_meter": datasets.Value("string"),
|
| 22 |
}),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
def _split_generators(self, dl_manager):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
return [
|
| 27 |
datasets.SplitGenerator(
|
| 28 |
name=datasets.Split.TRAIN,
|
| 29 |
+
gen_kwargs={"csv_file": f"data_train_{self.config.name}.csv"},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
),
|
| 31 |
]
|
| 32 |
|
| 33 |
+
def _generate_examples(self, csv_file):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
df = pd.read_csv(csv_file)
|
|
|
|
|
|
|
| 35 |
for idx, row in df.iterrows():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
yield idx, {
|
| 37 |
"filename": row["filename"],
|
| 38 |
+
"audio": row["filename"].lstrip("/"),
|
| 39 |
+
"label": row["label"],
|
| 40 |
+
"meter": str(row["meter"]),
|
| 41 |
+
"alt_meter": str(row["alt_meter"]),
|
| 42 |
}
|