Datasets:
Tasks:
Audio Classification
Sub-tasks:
multi-class-classification
Languages:
English
Size:
1K<n<10K
License:
Dragunflie-420
commited on
Commit
•
85e47e4
1
Parent(s):
4041d57
Update fma.py
Browse files
fma.py
CHANGED
@@ -41,6 +41,125 @@ _URLs = {
|
|
41 |
"metadata": "https://os.unil.cloud.switch.ch/fma/fma_metadata.zip",
|
42 |
}
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
class FMADataset(datasets.GeneratorBasedBuilder):
|
46 |
"""FMA small dataset."""
|
|
|
41 |
"metadata": "https://os.unil.cloud.switch.ch/fma/fma_metadata.zip",
|
42 |
}
|
43 |
|
44 |
+
class FMADataset(datasets.GeneratorBasedBuilder):
|
45 |
+
"""FMA small dataset."""
|
46 |
+
|
47 |
+
VERSION = datasets.Version("1.0.0")
|
48 |
+
|
49 |
+
BUILDER_CONFIGS = [
|
50 |
+
datasets.BuilderConfig(name="small", version=VERSION, description="The small subset of FMA dataset"),
|
51 |
+
]
|
52 |
+
|
53 |
+
def _info(self):
|
54 |
+
features = datasets.Features(
|
55 |
+
{
|
56 |
+
"track_id": datasets.Value("int32"),
|
57 |
+
"title": datasets.Value("string"),
|
58 |
+
"artist": datasets.Value("string"),
|
59 |
+
"genre": datasets.Value("string"),
|
60 |
+
"audio": datasets.Audio(sampling_rate=44100),
|
61 |
+
}
|
62 |
+
)
|
63 |
+
return datasets.DatasetInfo(
|
64 |
+
description=_DESCRIPTION,
|
65 |
+
features=features,
|
66 |
+
homepage=_HOMEPAGE,
|
67 |
+
license=_LICENSE,
|
68 |
+
citation=_CITATION,
|
69 |
+
)
|
70 |
+
|
71 |
+
def _split_generators(self, dl_manager):
|
72 |
+
"""Returns SplitGenerators."""
|
73 |
+
data_dir = dl_manager.download_and_extract(_URLs)
|
74 |
+
return [
|
75 |
+
datasets.SplitGenerator(
|
76 |
+
name=datasets.Split.TRAIN,
|
77 |
+
gen_kwargs={
|
78 |
+
"filepath": os.path.join(data_dir["small"], "fma_small"),
|
79 |
+
"metadata_path": os.path.join(data_dir["metadata"], "fma_metadata"),
|
80 |
+
},
|
81 |
+
),
|
82 |
+
]
|
83 |
+
|
84 |
+
def _generate_examples(self, filepath, metadata_path):
|
85 |
+
"""Yields examples."""
|
86 |
+
# Load metadata
|
87 |
+
tracks = pd.read_csv(os.path.join(metadata_path, "tracks.csv"), index_col=0, header=[0, 1])
|
88 |
+
|
89 |
+
# Iterate through audio files
|
90 |
+
for root, _, files in os.walk(filepath):
|
91 |
+
for file in files:
|
92 |
+
if file.endswith('.mp3'):
|
93 |
+
track_id = int(file.split('.')[0])
|
94 |
+
audio_path = os.path.join(root, file)
|
95 |
+
|
96 |
+
# Get metadata
|
97 |
+
title = tracks.loc[track_id, ('track', 'title')]
|
98 |
+
artist = tracks.loc[track_id, ('artist', 'name')]
|
99 |
+
genre = tracks.loc[track_id, ('track', 'genre_top')]
|
100 |
+
|
101 |
+
yield track_id, {
|
102 |
+
"track_id": track_id,
|
103 |
+
"title": title,
|
104 |
+
"artist": artist,
|
105 |
+
"genre": genre,
|
106 |
+
"audio": audio_path,
|
107 |
+
}
|
108 |
+
|
109 |
+
@property
|
110 |
+
def manual_download_instructions(self):
|
111 |
+
return """
|
112 |
+
To use the FMA dataset, you need to download it manually. Please follow these steps:
|
113 |
+
|
114 |
+
1. Go to https://github.com/mdeff/fma
|
115 |
+
2. Download the 'fma_small.zip' and 'fma_metadata.zip' files
|
116 |
+
3. Extract both zip files
|
117 |
+
4. Copy the 'fma_small' folder and the 'fma_metadata' folder to the root of this dataset repository
|
118 |
+
|
119 |
+
Once you have completed these steps, the dataset will be ready to use.
|
120 |
+
""" coding=utf-8
|
121 |
+
# Copyright 2024 The HuggingFace Datasets Authors and the current dataset script contributor.
|
122 |
+
#
|
123 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
124 |
+
# you may not use this file except in compliance with the License.
|
125 |
+
# You may obtain a copy of the License at
|
126 |
+
#
|
127 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
128 |
+
#
|
129 |
+
# Unless required by applicable law or agreed to in writing, software
|
130 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
131 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
132 |
+
# See the License for the specific language governing permissions and
|
133 |
+
# limitations under the License.
|
134 |
+
|
135 |
+
import os
|
136 |
+
import pandas as pd
|
137 |
+
import numpy as np
|
138 |
+
|
139 |
+
import datasets
|
140 |
+
|
141 |
+
_CITATION = """
|
142 |
+
@inproceedings{defferrard2016fma,
|
143 |
+
title={FMA: A Dataset for Music Analysis},
|
144 |
+
author={Defferrard, Micha{\"e}l and Benzi, Kirell and Vandergheynst, Pierre and Bresson, Xavier},
|
145 |
+
booktitle={18th International Society for Music Information Retrieval Conference},
|
146 |
+
year={2017},
|
147 |
+
}
|
148 |
+
"""
|
149 |
+
|
150 |
+
_DESCRIPTION = """
|
151 |
+
The Free Music Archive (FMA) is an open and easily accessible dataset of music collections.
|
152 |
+
"""
|
153 |
+
|
154 |
+
_HOMEPAGE = "https://github.com/mdeff/fma"
|
155 |
+
|
156 |
+
_LICENSE = "Creative Commons Attribution 4.0 International License"
|
157 |
+
|
158 |
+
_URLs = {
|
159 |
+
"small": "https://os.unil.cloud.switch.ch/fma/fma_small.zip",
|
160 |
+
"metadata": "https://os.unil.cloud.switch.ch/fma/fma_metadata.zip",
|
161 |
+
}
|
162 |
+
|
163 |
|
164 |
class FMADataset(datasets.GeneratorBasedBuilder):
|
165 |
"""FMA small dataset."""
|