Upload 4 files
Browse files- README.md +161 -0
- data/genres.tar.gz +3 -0
- gtzan.py +93 -0
- split_audio_files.py +144 -0
README.md
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
pretty_name: GTZAN
|
3 |
+
---
|
4 |
+
|
5 |
+
# Dataset Card for GTZAN
|
6 |
+
|
7 |
+
## Table of Contents
|
8 |
+
- [Dataset Card for GTZAN](#dataset-card-for-gtzan)
|
9 |
+
- [Table of Contents](#table-of-contents)
|
10 |
+
- [Dataset Description](#dataset-description)
|
11 |
+
- [Dataset Summary](#dataset-summary)
|
12 |
+
- [Languages](#languages)
|
13 |
+
- [Dataset Structure](#dataset-structure)
|
14 |
+
- [Data Instances](#data-instances)
|
15 |
+
- [Data Fields](#data-fields)
|
16 |
+
- [Data Splits](#data-splits)
|
17 |
+
- [Dataset Creation](#dataset-creation)
|
18 |
+
- [Curation Rationale](#curation-rationale)
|
19 |
+
- [Source Data](#source-data)
|
20 |
+
- [Initial Data Collection and Normalization](#initial-data-collection-and-normalization)
|
21 |
+
- [Who are the source language producers?](#who-are-the-source-language-producers)
|
22 |
+
- [Annotations](#annotations)
|
23 |
+
- [Annotation process](#annotation-process)
|
24 |
+
- [Who are the annotators?](#who-are-the-annotators)
|
25 |
+
- [Personal and Sensitive Information](#personal-and-sensitive-information)
|
26 |
+
- [Considerations for Using the Data](#considerations-for-using-the-data)
|
27 |
+
- [Social Impact of Dataset](#social-impact-of-dataset)
|
28 |
+
- [Discussion of Biases](#discussion-of-biases)
|
29 |
+
- [Other Known Limitations](#other-known-limitations)
|
30 |
+
- [Additional Information](#additional-information)
|
31 |
+
- [Dataset Curators](#dataset-curators)
|
32 |
+
- [Licensing Information](#licensing-information)
|
33 |
+
- [Citation Information](#citation-information)
|
34 |
+
- [Contributions](#contributions)
|
35 |
+
|
36 |
+
## Dataset Description
|
37 |
+
|
38 |
+
- **Homepage:** [http://marsyas.info/downloads/datasets.html](http://marsyas.info/downloads/datasets.html)
|
39 |
+
- **Paper:** [http://ismir2001.ismir.net/pdf/tzanetakis.pdf](http://ismir2001.ismir.net/pdf/tzanetakis.pdf)
|
40 |
+
- **Point of Contact:**
|
41 |
+
|
42 |
+
### Dataset Summary
|
43 |
+
|
44 |
+
GTZAN is a dataset for musical genre classification of audio signals. The dataset consists of 1,000 audio tracks, each of 30 seconds long. It contains 10 genres, each represented by 100 tracks. The tracks are all 22,050Hz Mono 16-bit audio files in WAV format. The genres are: blues, classical, country, disco, hiphop, jazz, metal, pop, reggae, and rock.
|
45 |
+
|
46 |
+
### Languages
|
47 |
+
|
48 |
+
English
|
49 |
+
|
50 |
+
## Dataset Structure
|
51 |
+
|
52 |
+
GTZAN is distributed as a single dataset without a predefined training and test split. The information below refers to the single `train` split that is assigned by default.
|
53 |
+
|
54 |
+
### Data Instances
|
55 |
+
|
56 |
+
An example of GTZAN looks as follows:
|
57 |
+
|
58 |
+
```python
|
59 |
+
{
|
60 |
+
"file": "/path/to/cache/genres/blues/blues.00000.wav",
|
61 |
+
"audio": {
|
62 |
+
"path": "/path/to/cache/genres/blues/blues.00000.wav",
|
63 |
+
"array": array(
|
64 |
+
[
|
65 |
+
0.00732422,
|
66 |
+
0.01660156,
|
67 |
+
0.00762939,
|
68 |
+
...,
|
69 |
+
-0.05560303,
|
70 |
+
-0.06106567,
|
71 |
+
-0.06417847,
|
72 |
+
],
|
73 |
+
dtype=float32,
|
74 |
+
),
|
75 |
+
"sampling_rate": 22050,
|
76 |
+
},
|
77 |
+
"genre": 0,
|
78 |
+
}
|
79 |
+
```
|
80 |
+
|
81 |
+
### Data Fields
|
82 |
+
|
83 |
+
The types associated with each of the data fields is as follows:
|
84 |
+
|
85 |
+
* `file`: a `string` feature.
|
86 |
+
* `audio`: an `Audio` feature containing the `path` of the sound file, the decoded waveform in the `array` field, and the `sampling_rate`.
|
87 |
+
* `genre`: a `ClassLabel` feature.
|
88 |
+
|
89 |
+
### Data Splits
|
90 |
+
|
91 |
+
[More Information Needed]
|
92 |
+
|
93 |
+
## Dataset Creation
|
94 |
+
|
95 |
+
### Curation Rationale
|
96 |
+
|
97 |
+
[More Information Needed]
|
98 |
+
|
99 |
+
### Source Data
|
100 |
+
|
101 |
+
#### Initial Data Collection and Normalization
|
102 |
+
|
103 |
+
[More Information Needed]
|
104 |
+
|
105 |
+
#### Who are the source language producers?
|
106 |
+
|
107 |
+
[More Information Needed]
|
108 |
+
|
109 |
+
### Annotations
|
110 |
+
|
111 |
+
#### Annotation process
|
112 |
+
|
113 |
+
[More Information Needed]
|
114 |
+
|
115 |
+
#### Who are the annotators?
|
116 |
+
|
117 |
+
[More Information Needed]
|
118 |
+
|
119 |
+
### Personal and Sensitive Information
|
120 |
+
|
121 |
+
[More Information Needed]
|
122 |
+
|
123 |
+
## Considerations for Using the Data
|
124 |
+
|
125 |
+
### Social Impact of Dataset
|
126 |
+
|
127 |
+
[More Information Needed]
|
128 |
+
|
129 |
+
### Discussion of Biases
|
130 |
+
|
131 |
+
[More Information Needed]
|
132 |
+
|
133 |
+
### Other Known Limitations
|
134 |
+
|
135 |
+
[More Information Needed]
|
136 |
+
|
137 |
+
## Additional Information
|
138 |
+
|
139 |
+
### Dataset Curators
|
140 |
+
|
141 |
+
[More Information Needed]
|
142 |
+
|
143 |
+
### Licensing Information
|
144 |
+
|
145 |
+
[More Information Needed]
|
146 |
+
|
147 |
+
### Citation Information
|
148 |
+
|
149 |
+
```
|
150 |
+
@misc{tzanetakis_essl_cook_2001,
|
151 |
+
author = "Tzanetakis, George and Essl, Georg and Cook, Perry",
|
152 |
+
title = "Automatic Musical Genre Classification Of Audio Signals",
|
153 |
+
url = "http://ismir2001.ismir.net/pdf/tzanetakis.pdf",
|
154 |
+
publisher = "The International Society for Music Information Retrieval",
|
155 |
+
year = "2001"
|
156 |
+
}
|
157 |
+
```
|
158 |
+
|
159 |
+
### Contributions
|
160 |
+
|
161 |
+
Thanks to [@lewtun](https://github.com/lewtun) for adding this dataset.
|
data/genres.tar.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:eba51f3ef481caf5a28e6e86189857ca9da8aee47a6257742edded1341f01704
|
3 |
+
size 1220194162
|
gtzan.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
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 |
+
"""The GTZAN dataset."""
|
15 |
+
|
16 |
+
|
17 |
+
from pathlib import Path
|
18 |
+
|
19 |
+
import datasets
|
20 |
+
import pandas as pd
|
21 |
+
|
22 |
+
_CITATION = """\
|
23 |
+
@misc{tzanetakis_essl_cook_2001,
|
24 |
+
author = "Tzanetakis, George and Essl, Georg and Cook, Perry",
|
25 |
+
title = "Automatic Musical Genre Classification Of Audio Signals",
|
26 |
+
url = "http://ismir2001.ismir.net/pdf/tzanetakis.pdf",
|
27 |
+
publisher = "The International Society for Music Information Retrieval",
|
28 |
+
year = "2001"
|
29 |
+
}
|
30 |
+
"""
|
31 |
+
|
32 |
+
|
33 |
+
_DESCRIPTION = """\
|
34 |
+
GTZAN is a dataset for musical genre classification of audio signals. The dataset consists of 1,000 audio tracks, each of 30 seconds long. It contains 10 genres, each represented by 100 tracks. The tracks are all 22,050Hz Mono 16-bit audio files in WAV format. The genres are: blues, classical, country, disco, hiphop, jazz, metal, pop, reggae, and rock.
|
35 |
+
"""
|
36 |
+
|
37 |
+
_HOMEPAGE = "http://marsyas.info/downloads/datasets.html"
|
38 |
+
|
39 |
+
# TODO: Add the licence for the dataset here if you can find it
|
40 |
+
_LICENSE = ""
|
41 |
+
|
42 |
+
_URL = "http://opihi.cs.uvic.ca/sound/genres.tar.gz"
|
43 |
+
|
44 |
+
GENRES = ["blues", "classical", "country", "disco", "hiphop", "jazz", "metal", "pop", "reggae", "rock"]
|
45 |
+
CORRUPTED_FILES = ["jazz.00054.wav"]
|
46 |
+
|
47 |
+
|
48 |
+
class Gtzan(datasets.GeneratorBasedBuilder):
|
49 |
+
"""The GTZAn dataset"""
|
50 |
+
|
51 |
+
def _info(self):
|
52 |
+
return datasets.DatasetInfo(
|
53 |
+
description=_DESCRIPTION,
|
54 |
+
features=datasets.Features(
|
55 |
+
{
|
56 |
+
"file": datasets.Value("string"),
|
57 |
+
"audio": datasets.Audio(sampling_rate=22_050),
|
58 |
+
"genre": datasets.ClassLabel(names=GENRES),
|
59 |
+
}
|
60 |
+
),
|
61 |
+
homepage=_HOMEPAGE,
|
62 |
+
license=_LICENSE,
|
63 |
+
citation=_CITATION,
|
64 |
+
)
|
65 |
+
|
66 |
+
def _split_generators(self, dl_manager):
|
67 |
+
local_extracted_archive = dl_manager.download_and_extract("data/genres.tar.gz")
|
68 |
+
return [
|
69 |
+
datasets.SplitGenerator(
|
70 |
+
name=datasets.Split.TRAIN,
|
71 |
+
gen_kwargs={
|
72 |
+
"local_extracted_archive": local_extracted_archive,
|
73 |
+
},
|
74 |
+
)
|
75 |
+
]
|
76 |
+
|
77 |
+
def _generate_examples(self, local_extracted_archive):
|
78 |
+
paths = list(Path(local_extracted_archive).glob("**/*.wav"))
|
79 |
+
paths = [p for p in paths if "._" not in p.name]
|
80 |
+
data = []
|
81 |
+
|
82 |
+
for path in paths:
|
83 |
+
label = str(path).split("/")[-2]
|
84 |
+
name = str(path).split("/")[-1]
|
85 |
+
if name in CORRUPTED_FILES:
|
86 |
+
continue
|
87 |
+
|
88 |
+
data.append({"file": str(path), "genre": label})
|
89 |
+
df = pd.DataFrame(data)
|
90 |
+
df.sort_values("file", inplace=True)
|
91 |
+
|
92 |
+
for idx_, row in df.iterrows():
|
93 |
+
yield idx_, {"file": row["file"], "audio": row["file"], "genre": row["genre"]}
|
split_audio_files.py
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import librosa
|
3 |
+
import soundfile as sf
|
4 |
+
|
5 |
+
# Define the input directory relative to the current working directory
|
6 |
+
input_dir = os.path.join(os.getcwd(), 'data', 'genres') # Assumes the genres folder is inside the data folder
|
7 |
+
|
8 |
+
# Define the output directory relative to the current working directory
|
9 |
+
output_dir = os.path.join(os.getcwd(), 'data_5') # Replace 'output' with your desired output directory name
|
10 |
+
|
11 |
+
# Create the output directory if it doesn't exist
|
12 |
+
os.makedirs(output_dir, exist_ok=True)
|
13 |
+
|
14 |
+
# Define the segment duration in seconds
|
15 |
+
segment_duration = 5
|
16 |
+
|
17 |
+
# Iterate over the genre folders in the input directory
|
18 |
+
for genre_folder in os.listdir(input_dir):
|
19 |
+
print(f"Genre: {genre_folder} @ {segment_duration} seconds")
|
20 |
+
genre_path = os.path.join(input_dir, genre_folder)
|
21 |
+
|
22 |
+
# Create a corresponding genre folder in the output directory
|
23 |
+
output_genre_path = os.path.join(output_dir, genre_folder)
|
24 |
+
os.makedirs(output_genre_path, exist_ok=True)
|
25 |
+
|
26 |
+
# Iterate over all audio files in the genre folder
|
27 |
+
for filename in os.listdir(genre_path):
|
28 |
+
file_path = os.path.join(genre_path, filename)
|
29 |
+
|
30 |
+
# Check if the file is in WAV format
|
31 |
+
if filename.endswith('.wav'):
|
32 |
+
# Load the audio file using Librosa
|
33 |
+
audio, sr = librosa.load(file_path)
|
34 |
+
|
35 |
+
# Calculate the total number of segments
|
36 |
+
num_segments = len(audio) // (sr * segment_duration)
|
37 |
+
|
38 |
+
# Divide the audio into segments and save them individually
|
39 |
+
for i in range(num_segments):
|
40 |
+
start_sample = i * sr * segment_duration
|
41 |
+
end_sample = start_sample + sr * segment_duration
|
42 |
+
segment = audio[start_sample:end_sample]
|
43 |
+
|
44 |
+
# Create a new filename for the segment
|
45 |
+
segment_filename = f"{filename[:-4]}_{i+1}.wav"
|
46 |
+
|
47 |
+
# Save the segment to the genre folder in the output directory
|
48 |
+
segment_path = os.path.join(output_genre_path, segment_filename)
|
49 |
+
sf.write(segment_path, segment, sr)
|
50 |
+
else:
|
51 |
+
print(f"Skipping {filename} as it is not a WAV file.")
|
52 |
+
|
53 |
+
|
54 |
+
# Define the output directory relative to the current working directory
|
55 |
+
output_dir = os.path.join(os.getcwd(), 'data_10') # Replace 'output' with your desired output directory name
|
56 |
+
|
57 |
+
# Create the output directory if it doesn't exist
|
58 |
+
os.makedirs(output_dir, exist_ok=True)
|
59 |
+
|
60 |
+
# Define the segment duration in seconds
|
61 |
+
segment_duration = 10
|
62 |
+
|
63 |
+
# Iterate over the genre folders in the input directory
|
64 |
+
for genre_folder in os.listdir(input_dir):
|
65 |
+
print(f"Genre: {genre_folder} @ {segment_duration} seconds")
|
66 |
+
genre_path = os.path.join(input_dir, genre_folder)
|
67 |
+
|
68 |
+
# Create a corresponding genre folder in the output directory
|
69 |
+
output_genre_path = os.path.join(output_dir, genre_folder)
|
70 |
+
os.makedirs(output_genre_path, exist_ok=True)
|
71 |
+
|
72 |
+
# Iterate over all audio files in the genre folder
|
73 |
+
for filename in os.listdir(genre_path):
|
74 |
+
file_path = os.path.join(genre_path, filename)
|
75 |
+
|
76 |
+
# Check if the file is in WAV format
|
77 |
+
if filename.endswith('.wav'):
|
78 |
+
# Load the audio file using Librosa
|
79 |
+
audio, sr = librosa.load(file_path)
|
80 |
+
|
81 |
+
# Calculate the total number of segments
|
82 |
+
num_segments = len(audio) // (sr * segment_duration)
|
83 |
+
|
84 |
+
# Divide the audio into segments and save them individually
|
85 |
+
for i in range(num_segments):
|
86 |
+
start_sample = i * sr * segment_duration
|
87 |
+
end_sample = start_sample + sr * segment_duration
|
88 |
+
segment = audio[start_sample:end_sample]
|
89 |
+
|
90 |
+
# Create a new filename for the segment
|
91 |
+
segment_filename = f"{filename[:-4]}_{i+1}.wav"
|
92 |
+
|
93 |
+
# Save the segment to the genre folder in the output directory
|
94 |
+
segment_path = os.path.join(output_genre_path, segment_filename)
|
95 |
+
sf.write(segment_path, segment, sr)
|
96 |
+
else:
|
97 |
+
print(f"Skipping {filename} as it is not a WAV file.")
|
98 |
+
|
99 |
+
|
100 |
+
# Define the output directory relative to the current working directory
|
101 |
+
output_dir = os.path.join(os.getcwd(), 'data_15') # Replace 'output' with your desired output directory name
|
102 |
+
|
103 |
+
# Create the output directory if it doesn't exist
|
104 |
+
os.makedirs(output_dir, exist_ok=True)
|
105 |
+
|
106 |
+
# Define the segment duration in seconds
|
107 |
+
segment_duration = 15
|
108 |
+
|
109 |
+
# Iterate over the genre folders in the input directory
|
110 |
+
for genre_folder in os.listdir(input_dir):
|
111 |
+
print(f"Genre: {genre_folder} @ {segment_duration} seconds")
|
112 |
+
genre_path = os.path.join(input_dir, genre_folder)
|
113 |
+
|
114 |
+
# Create a corresponding genre folder in the output directory
|
115 |
+
output_genre_path = os.path.join(output_dir, genre_folder)
|
116 |
+
os.makedirs(output_genre_path, exist_ok=True)
|
117 |
+
|
118 |
+
# Iterate over all audio files in the genre folder
|
119 |
+
for filename in os.listdir(genre_path):
|
120 |
+
file_path = os.path.join(genre_path, filename)
|
121 |
+
|
122 |
+
# Check if the file is in WAV format
|
123 |
+
if filename.endswith('.wav'):
|
124 |
+
# Load the audio file using Librosa
|
125 |
+
audio, sr = librosa.load(file_path)
|
126 |
+
|
127 |
+
# Calculate the total number of segments
|
128 |
+
num_segments = len(audio) // (sr * segment_duration)
|
129 |
+
|
130 |
+
# Divide the audio into segments and save them individually
|
131 |
+
for i in range(num_segments):
|
132 |
+
start_sample = i * sr * segment_duration
|
133 |
+
end_sample = start_sample + sr * segment_duration
|
134 |
+
segment = audio[start_sample:end_sample]
|
135 |
+
|
136 |
+
# Create a new filename for the segment
|
137 |
+
segment_filename = f"{filename[:-4]}_{i+1}.wav"
|
138 |
+
|
139 |
+
# Save the segment to the genre folder in the output directory
|
140 |
+
segment_path = os.path.join(output_genre_path, segment_filename)
|
141 |
+
sf.write(segment_path, segment, sr)
|
142 |
+
else:
|
143 |
+
print(f"Skipping {filename} as it is not a WAV file.")
|
144 |
+
|