mmzoellner commited on
Commit
912bcaf
·
verified ·
1 Parent(s): e7547eb

Upload ATD2.py

Browse files
Files changed (1) hide show
  1. ATD2.py +59 -0
ATD2.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ from datasets import GeneratorBasedBuilder, DatasetInfo, Split, SplitGenerator, Features, Value, Audio
4
+
5
+ # Code on HF used for dataset gen
6
+
7
+ class ATD2(GeneratorBasedBuilder):
8
+
9
+ def _info(self):
10
+ return DatasetInfo(
11
+ description="Audio classification dataset with 10 folds and metadata.",
12
+ features=Features({
13
+ "audio": Audio(),
14
+ "label": Value("string"),
15
+ "audio_path": Value("string"),
16
+ "fold": Value("int32")
17
+ }),
18
+ supervised_keys=("audio", "label"),
19
+ )
20
+
21
+ def _split_generators(self, dl_manager):
22
+ print(" _split_generators running...")
23
+
24
+ extracted_dir = dl_manager.download_and_extract(
25
+ "https://huggingface.co/datasets/mmzoellner/ATD2/resolve/main/folds.tar"
26
+ )
27
+ metadata_path = dl_manager.download(
28
+ "https://huggingface.co/datasets/mmzoellner/ATD2/resolve/main/metadata.csv"
29
+ )
30
+
31
+ return [
32
+ SplitGenerator(
33
+ name=Split.TRAIN,
34
+ gen_kwargs={
35
+ "archive_path": extracted_dir,
36
+ "metadata_path": metadata_path
37
+ }
38
+ )
39
+ ]
40
+
41
+ def _generate_examples(self, archive_path, metadata_path):
42
+ print(" _generate_examples is running...")
43
+ df = pd.read_csv(metadata_path)
44
+
45
+ for idx, row in df.iterrows():
46
+ corrected_path = row["audio_path"].replace("audio/", "")
47
+ full_path = os.path.join(archive_path, corrected_path)
48
+
49
+ if not os.path.isfile(full_path):
50
+ print(f"Missing: {full_path}")
51
+ continue
52
+
53
+ yield idx, {
54
+ "audio": full_path,
55
+ "label": row["label"],
56
+ "audio_path": corrected_path,
57
+ "fold": int(row["fold"]),
58
+ }
59
+ print("done.")