Datasets:
Size:
10K<n<100K
License:
Monet Joe
commited on
Commit
•
84b0e54
1
Parent(s):
1260e00
Upload 2 files
Browse files- data/data.zip +3 -0
- music_genre.py +47 -33
data/data.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7484d529402647aaff937494e3254bb4a46ef2f95ef4804e3ab9d5e6566a5b0b
|
3 |
+
size 4358927179
|
music_genre.py
CHANGED
@@ -55,11 +55,7 @@ This database contains about 1700 musical pieces (.mp3 format)
|
|
55 |
with lengths of 270-300s that are divided into 17 genres in total.
|
56 |
"""
|
57 |
|
58 |
-
|
59 |
-
"mel": _HOMEPAGE + "/resolve/main/data/mel.zip",
|
60 |
-
"cqt": _HOMEPAGE + "/resolve/main/data/cqt.zip",
|
61 |
-
"chroma": _HOMEPAGE + "/resolve/main/data/chroma.zip"
|
62 |
-
}
|
63 |
|
64 |
|
65 |
class music_genre(datasets.GeneratorBasedBuilder):
|
@@ -68,6 +64,8 @@ class music_genre(datasets.GeneratorBasedBuilder):
|
|
68 |
features=datasets.Features(
|
69 |
{
|
70 |
"mel": datasets.Image(),
|
|
|
|
|
71 |
"fst_level_label": datasets.features.ClassLabel(names=list(_NAMES_1.values())),
|
72 |
"sec_level_label": datasets.features.ClassLabel(names=list(_NAMES_2.values())),
|
73 |
"thr_level_label": datasets.features.ClassLabel(names=list(_NAMES_3.values()))
|
@@ -88,29 +86,43 @@ class music_genre(datasets.GeneratorBasedBuilder):
|
|
88 |
)
|
89 |
|
90 |
def _split_generators(self, dl_manager):
|
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 |
def _calc_label(self, path, depth, substr='/mel/'):
|
116 |
spect = substr
|
@@ -130,11 +142,13 @@ class music_genre(datasets.GeneratorBasedBuilder):
|
|
130 |
else:
|
131 |
return 0
|
132 |
|
133 |
-
def _generate_examples(self, files
|
134 |
for i, path in enumerate(files):
|
135 |
yield i, {
|
136 |
-
"mel": path,
|
137 |
-
"
|
138 |
-
"
|
139 |
-
"
|
|
|
|
|
140 |
}
|
|
|
55 |
with lengths of 270-300s that are divided into 17 genres in total.
|
56 |
"""
|
57 |
|
58 |
+
_URL = _HOMEPAGE + "/resolve/main/data/data.zip"
|
|
|
|
|
|
|
|
|
59 |
|
60 |
|
61 |
class music_genre(datasets.GeneratorBasedBuilder):
|
|
|
64 |
features=datasets.Features(
|
65 |
{
|
66 |
"mel": datasets.Image(),
|
67 |
+
"cqt": datasets.Image(),
|
68 |
+
"chroma": datasets.Image(),
|
69 |
"fst_level_label": datasets.features.ClassLabel(names=list(_NAMES_1.values())),
|
70 |
"sec_level_label": datasets.features.ClassLabel(names=list(_NAMES_2.values())),
|
71 |
"thr_level_label": datasets.features.ClassLabel(names=list(_NAMES_3.values()))
|
|
|
86 |
)
|
87 |
|
88 |
def _split_generators(self, dl_manager):
|
89 |
+
data_files = dl_manager.download_and_extract(_URL)
|
90 |
+
files = dl_manager.iter_files([data_files])
|
91 |
+
|
92 |
+
dataset = []
|
93 |
+
for path in files:
|
94 |
+
if os.path.basename(path).endswith(".jpg"):
|
95 |
+
dataset.append({
|
96 |
+
'mel': path,
|
97 |
+
'cqt': path.replace('\\mel\\', '\\cqt\\').replace('/mel/', '/cqt/'),
|
98 |
+
'chroma': path.replace('\\mel\\', '\\chroma\\').replace('/mel/', '/chroma/')
|
99 |
+
})
|
100 |
+
|
101 |
+
random.shuffle(dataset)
|
102 |
+
data_count = len(dataset)
|
103 |
+
p80 = int(data_count * 0.8)
|
104 |
+
p90 = int(data_count * 0.9)
|
105 |
+
|
106 |
+
return [
|
107 |
+
datasets.SplitGenerator(
|
108 |
+
name=datasets.Split.TRAIN,
|
109 |
+
gen_kwargs={
|
110 |
+
"files": dataset[:p80]
|
111 |
+
},
|
112 |
+
),
|
113 |
+
datasets.SplitGenerator(
|
114 |
+
name=datasets.Split.VALIDATION,
|
115 |
+
gen_kwargs={
|
116 |
+
"files": dataset[p80:p90]
|
117 |
+
},
|
118 |
+
),
|
119 |
+
datasets.SplitGenerator(
|
120 |
+
name=datasets.Split.TEST,
|
121 |
+
gen_kwargs={
|
122 |
+
"files": dataset[p90:]
|
123 |
+
},
|
124 |
+
),
|
125 |
+
]
|
126 |
|
127 |
def _calc_label(self, path, depth, substr='/mel/'):
|
128 |
spect = substr
|
|
|
142 |
else:
|
143 |
return 0
|
144 |
|
145 |
+
def _generate_examples(self, files):
|
146 |
for i, path in enumerate(files):
|
147 |
yield i, {
|
148 |
+
"mel": path['mel'],
|
149 |
+
"cqt": path['cqt'],
|
150 |
+
"chroma": path['chroma'],
|
151 |
+
"fst_level_label": _NAMES_1[self._calc_label(path['mel'], 1)],
|
152 |
+
"sec_level_label": _NAMES_2[self._calc_label(path['mel'], 2)],
|
153 |
+
"thr_level_label": _NAMES_3[self._calc_label(path['mel'], 3)]
|
154 |
}
|