danilotpnta commited on
Commit
2684475
1 Parent(s): 393830f
Files changed (3) hide show
  1. .gitignore +1 -0
  2. GTZAN_genre_classification.py +114 -0
  3. metadata.csv +0 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ data/.DS_Store
GTZAN_genre_classification.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import csv
3
+ import datasets
4
+
5
+ logger = datasets.logging.get_logger(__name__)
6
+
7
+ _CITATION = """\
8
+ @misc{gtzan2023,
9
+ title={GTZAN Music Genre Classification Dataset},
10
+ author={Your Name},
11
+ year={2023},
12
+ url={https://example.com},
13
+ }
14
+ """
15
+
16
+ _DESCRIPTION = """\
17
+ The GTZAN dataset is a music genre classification dataset.
18
+ It consists of 10 genres, each represented by 100 tracks.
19
+ """
20
+
21
+ _HOMEPAGE_URL = "https://example.com"
22
+ _DATA_URL = "data/gtzan.zip"
23
+
24
+ class GTZANConfig(datasets.BuilderConfig):
25
+ """BuilderConfig for GTZAN"""
26
+
27
+ def __init__(self, **kwargs):
28
+ super(GTZANConfig, self).__init__(**kwargs)
29
+
30
+
31
+ class GTZAN(datasets.GeneratorBasedBuilder):
32
+ BUILDER_CONFIGS = [
33
+ GTZANConfig(name="gtzan", version=datasets.Version("1.0.0"), description="GTZAN Music Genre Classification Dataset")
34
+ ]
35
+
36
+ def _info(self):
37
+ return datasets.DatasetInfo(
38
+ description=_DESCRIPTION,
39
+ features=datasets.Features(
40
+ {
41
+ "id": datasets.Value("int32"),
42
+ "genre": datasets.Value("string"),
43
+ "title": datasets.Value("string"),
44
+ "artist": datasets.Value("string"),
45
+ "tempo": datasets.Value("float"),
46
+ "keys": datasets.Value("string"),
47
+ "loudness": datasets.Value("float"),
48
+ "embeddings": datasets.Value("string"),
49
+ "sorted_pred_genres": datasets.Value("string"),
50
+ "x_tsne": datasets.Value("float"),
51
+ "y_tsne": datasets.Value("float"),
52
+ "z_tsne": datasets.Value("float"),
53
+ "x_umap": datasets.Value("float"),
54
+ "y_umap": datasets.Value("float"),
55
+ "z_umap": datasets.Value("float"),
56
+ "album_cover_path": datasets.Value("string"),
57
+ "key": datasets.Value("string"),
58
+ "filepath": datasets.Value("string"),
59
+ "audio": datasets.Audio(sampling_rate=44100),
60
+ }
61
+ ),
62
+ supervised_keys=("audio", "genre"),
63
+ homepage=_HOMEPAGE_URL,
64
+ citation=_CITATION,
65
+ )
66
+
67
+ def _split_generators(self, dl_manager):
68
+ archive_path = dl_manager.download_and_extract(_DATA_URL)
69
+ data_dir = os.path.join(archive_path, "gtzan")
70
+
71
+ # Debugging the paths
72
+ logger.info(f"Archive path: {archive_path}")
73
+ logger.info(f"Data directory: {data_dir}")
74
+
75
+ return [
76
+ datasets.SplitGenerator(
77
+ name=datasets.Split.TRAIN,
78
+ gen_kwargs={
79
+ "metadata_file": os.path.join(data_dir, "metadata.csv"),
80
+ "data_dir": data_dir,
81
+ },
82
+ ),
83
+ ]
84
+
85
+ def _generate_examples(self, metadata_file, data_dir):
86
+ with open(metadata_file, "r", encoding="utf-8") as f:
87
+ reader = csv.DictReader(f)
88
+ for id_, row in enumerate(reader):
89
+ file_path = os.path.join(data_dir, row["filepath"])
90
+
91
+ # Debugging the file paths
92
+ logger.info(f"Processing file: {file_path}")
93
+
94
+ yield id_, {
95
+ "id": int(row["id"]),
96
+ "genre": row["genre"],
97
+ "title": row["title"],
98
+ "artist": row["artist"],
99
+ "tempo": float(row["tempo"]),
100
+ "keys": row["keys"],
101
+ "loudness": float(row["loudness"]),
102
+ "embeddings": row["embeddings"],
103
+ "sorted_pred_genres": row["sorted_pred_genres"],
104
+ "x_tsne": float(row["x_tsne"]),
105
+ "y_tsne": float(row["y_tsne"]),
106
+ "z_tsne": float(row["z_tsne"]),
107
+ "x_umap": float(row["x_umap"]),
108
+ "y_umap": float(row["y_umap"]),
109
+ "z_umap": float(row["z_umap"]),
110
+ "album_cover_path": os.path.join(data_dir, row["album_cover_path"]),
111
+ "key": row["key"],
112
+ "filepath": file_path,
113
+ "audio": file_path,
114
+ }
metadata.csv ADDED
The diff for this file is too large to render. See raw diff