Update pianos.py
Browse files
pianos.py
CHANGED
|
@@ -57,6 +57,18 @@ class PianosConfig(datasets.BuilderConfig):
|
|
| 57 |
class pianos(datasets.GeneratorBasedBuilder):
|
| 58 |
|
| 59 |
BUILDER_CONFIGS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
PianosConfig(
|
| 61 |
features=datasets.Features(
|
| 62 |
{
|
|
@@ -84,19 +96,28 @@ class pianos(datasets.GeneratorBasedBuilder):
|
|
| 84 |
def _split_generators(self, dl_manager):
|
| 85 |
data_files = dl_manager.extract(_COMPRESSED_FILENAME)
|
| 86 |
dataset = []
|
| 87 |
-
|
| 88 |
for path in dl_manager.iter_files([data_files]):
|
| 89 |
fname = os.path.basename(path)
|
| 90 |
if fname.endswith(".wav"):
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
random.shuffle(dataset)
|
| 102 |
count = len(dataset)
|
|
@@ -117,9 +138,19 @@ class pianos(datasets.GeneratorBasedBuilder):
|
|
| 117 |
|
| 118 |
def _generate_examples(self, files):
|
| 119 |
for guid, path in enumerate(files):
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
class pianos(datasets.GeneratorBasedBuilder):
|
| 58 |
|
| 59 |
BUILDER_CONFIGS = [
|
| 60 |
+
PianosConfig(
|
| 61 |
+
features=datasets.Features(
|
| 62 |
+
{
|
| 63 |
+
"file": datasets.Value("string"),
|
| 64 |
+
"audio": datasets.Audio(sampling_rate=SAMPLE_RATE),
|
| 65 |
+
"sound": datasets.Value("string"),
|
| 66 |
+
"label": datasets.ClassLabel(names=_NAMES),
|
| 67 |
+
}
|
| 68 |
+
),
|
| 69 |
+
name="sound",
|
| 70 |
+
description=textwrap.dedent(_DESCRIPTION),
|
| 71 |
+
),
|
| 72 |
PianosConfig(
|
| 73 |
features=datasets.Features(
|
| 74 |
{
|
|
|
|
| 96 |
def _split_generators(self, dl_manager):
|
| 97 |
data_files = dl_manager.extract(_COMPRESSED_FILENAME)
|
| 98 |
dataset = []
|
| 99 |
+
|
| 100 |
for path in dl_manager.iter_files([data_files]):
|
| 101 |
fname = os.path.basename(path)
|
| 102 |
if fname.endswith(".wav"):
|
| 103 |
+
if self.config.name == "sound":
|
| 104 |
+
dataset.append(
|
| 105 |
+
{
|
| 106 |
+
"file": path,
|
| 107 |
+
"audio": path,
|
| 108 |
+
"label": os.path.basename(os.path.dirname(path)),
|
| 109 |
+
"sound": os.path.basename(os.path.dirname(path)),
|
| 110 |
+
}
|
| 111 |
+
)
|
| 112 |
+
elif self.config.name == "pitch":
|
| 113 |
+
dataset.append(
|
| 114 |
+
{
|
| 115 |
+
"file": path,
|
| 116 |
+
"audio": path,
|
| 117 |
+
"label": _PITCHES[fname.split("_")[0]],
|
| 118 |
+
"pitch": _PITCHES[fname.split("_")[0]],
|
| 119 |
+
}
|
| 120 |
+
)
|
| 121 |
|
| 122 |
random.shuffle(dataset)
|
| 123 |
count = len(dataset)
|
|
|
|
| 138 |
|
| 139 |
def _generate_examples(self, files):
|
| 140 |
for guid, path in enumerate(files):
|
| 141 |
+
if self.config.name == "sound":
|
| 142 |
+
yield guid, {
|
| 143 |
+
"id": str(guid),
|
| 144 |
+
"file": path["file"],
|
| 145 |
+
"audio": path["audio"],
|
| 146 |
+
"label": path["label"],
|
| 147 |
+
"sound": path["sound"],
|
| 148 |
+
}
|
| 149 |
+
elif self.config.name == "pitch":
|
| 150 |
+
yield guid, {
|
| 151 |
+
"id": str(guid),
|
| 152 |
+
"file": path["file"],
|
| 153 |
+
"audio": path["audio"],
|
| 154 |
+
"label": path["label"],
|
| 155 |
+
"pitch": path["pitch"],
|
| 156 |
+
}
|