Datasets:
Tasks:
Audio Classification
Sub-tasks:
multi-class-classification
Languages:
English
Size:
1K<n<10K
License:
File size: 8,083 Bytes
fa33463 85e47e4 fa33463 |
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 |
# coding=utf-8
# Copyright 2024 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.
import os
import pandas as pd
import numpy as np
import datasets
_CITATION = """
@inproceedings{defferrard2016fma,
title={FMA: A Dataset for Music Analysis},
author={Defferrard, Micha{\"e}l and Benzi, Kirell and Vandergheynst, Pierre and Bresson, Xavier},
booktitle={18th International Society for Music Information Retrieval Conference},
year={2017},
}
"""
_DESCRIPTION = """
The Free Music Archive (FMA) is an open and easily accessible dataset of music collections.
"""
_HOMEPAGE = "https://github.com/mdeff/fma"
_LICENSE = "Creative Commons Attribution 4.0 International License"
_URLs = {
"small": "https://os.unil.cloud.switch.ch/fma/fma_small.zip",
"metadata": "https://os.unil.cloud.switch.ch/fma/fma_metadata.zip",
}
class FMADataset(datasets.GeneratorBasedBuilder):
"""FMA small dataset."""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="small", version=VERSION, description="The small subset of FMA dataset"),
]
def _info(self):
features = datasets.Features(
{
"track_id": datasets.Value("int32"),
"title": datasets.Value("string"),
"artist": datasets.Value("string"),
"genre": datasets.Value("string"),
"audio": datasets.Audio(sampling_rate=44100),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_dir = dl_manager.download_and_extract(_URLs)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": os.path.join(data_dir["small"], "fma_small"),
"metadata_path": os.path.join(data_dir["metadata"], "fma_metadata"),
},
),
]
def _generate_examples(self, filepath, metadata_path):
"""Yields examples."""
# Load metadata
tracks = pd.read_csv(os.path.join(metadata_path, "tracks.csv"), index_col=0, header=[0, 1])
# Iterate through audio files
for root, _, files in os.walk(filepath):
for file in files:
if file.endswith('.mp3'):
track_id = int(file.split('.')[0])
audio_path = os.path.join(root, file)
# Get metadata
title = tracks.loc[track_id, ('track', 'title')]
artist = tracks.loc[track_id, ('artist', 'name')]
genre = tracks.loc[track_id, ('track', 'genre_top')]
yield track_id, {
"track_id": track_id,
"title": title,
"artist": artist,
"genre": genre,
"audio": audio_path,
}
@property
def manual_download_instructions(self):
return """
To use the FMA dataset, you need to download it manually. Please follow these steps:
1. Go to https://github.com/mdeff/fma
2. Download the 'fma_small.zip' and 'fma_metadata.zip' files
3. Extract both zip files
4. Copy the 'fma_small' folder and the 'fma_metadata' folder to the root of this dataset repository
Once you have completed these steps, the dataset will be ready to use.
""" coding=utf-8
# Copyright 2024 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.
import os
import pandas as pd
import numpy as np
import datasets
_CITATION = """
@inproceedings{defferrard2016fma,
title={FMA: A Dataset for Music Analysis},
author={Defferrard, Micha{\"e}l and Benzi, Kirell and Vandergheynst, Pierre and Bresson, Xavier},
booktitle={18th International Society for Music Information Retrieval Conference},
year={2017},
}
"""
_DESCRIPTION = """
The Free Music Archive (FMA) is an open and easily accessible dataset of music collections.
"""
_HOMEPAGE = "https://github.com/mdeff/fma"
_LICENSE = "Creative Commons Attribution 4.0 International License"
_URLs = {
"small": "https://os.unil.cloud.switch.ch/fma/fma_small.zip",
"metadata": "https://os.unil.cloud.switch.ch/fma/fma_metadata.zip",
}
class FMADataset(datasets.GeneratorBasedBuilder):
"""FMA small dataset."""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="small", version=VERSION, description="The small subset of FMA dataset"),
]
def _info(self):
features = datasets.Features(
{
"track_id": datasets.Value("int32"),
"title": datasets.Value("string"),
"artist": datasets.Value("string"),
"genre": datasets.Value("string"),
"audio": datasets.Audio(sampling_rate=44100),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_dir = dl_manager.download_and_extract(_URLs)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": os.path.join(data_dir["small"], "fma_small"),
"metadata_path": os.path.join(data_dir["metadata"], "fma_metadata"),
},
),
]
def _generate_examples(self, filepath, metadata_path):
"""Yields examples."""
# Load metadata
tracks = pd.read_csv(os.path.join(metadata_path, "tracks.csv"), index_col=0, header=[0, 1])
# Iterate through audio files
for root, _, files in os.walk(filepath):
for file in files:
if file.endswith('.mp3'):
track_id = int(file.split('.')[0])
audio_path = os.path.join(root, file)
# Get metadata
title = tracks.loc[track_id, ('track', 'title')]
artist = tracks.loc[track_id, ('artist', 'name')]
genre = tracks.loc[track_id, ('track', 'genre_top')]
yield track_id, {
"track_id": track_id,
"title": title,
"artist": artist,
"genre": genre,
"audio": audio_path,
} |