Datasets:
Add files using upload-large-folder tool
Browse files- example.py +14 -12
example.py
CHANGED
|
@@ -12,6 +12,7 @@ each with a `train` and `test` split.
|
|
| 12 |
metadata/test_pairs.csv, each with a seen/unseen condition.
|
| 13 |
"""
|
| 14 |
import csv
|
|
|
|
| 15 |
from datasets import load_dataset
|
| 16 |
from huggingface_hub import hf_hub_download
|
| 17 |
|
|
@@ -29,22 +30,23 @@ wav, sr = clip["audio"]["array"], clip["audio"]["sampling_rate"] # numpy wavef
|
|
| 29 |
print(f" designed (streamed): {clip['file_path']} | preset {clip['preset']}")
|
| 30 |
|
| 31 |
# -------------------------------------------------------------------- TEST
|
| 32 |
-
# Parallel: pair each source with its reference
|
| 33 |
-
|
| 34 |
-
|
|
|
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
ref_idx = {p: i for i, p in enumerate(references["file_path"])}
|
| 39 |
|
|
|
|
| 40 |
pairs_csv = hf_hub_download(REPO, "metadata/test_pairs.csv", repo_type="dataset")
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
-
for
|
| 45 |
-
source =
|
| 46 |
-
reference = references[ref_idx[pair["reference"]]]
|
| 47 |
src_wav = source["audio"]["array"]
|
| 48 |
ref_wav = reference["audio"]["array"]
|
| 49 |
-
print(f" [{
|
|
|
|
| 50 |
# ... compute your voice-conversion metric between src_wav and ref_wav ...
|
|
|
|
| 12 |
metadata/test_pairs.csv, each with a seen/unseen condition.
|
| 13 |
"""
|
| 14 |
import csv
|
| 15 |
+
from itertools import islice
|
| 16 |
from datasets import load_dataset
|
| 17 |
from huggingface_hub import hf_hub_download
|
| 18 |
|
|
|
|
| 30 |
print(f" designed (streamed): {clip['file_path']} | preset {clip['preset']}")
|
| 31 |
|
| 32 |
# -------------------------------------------------------------------- TEST
|
| 33 |
+
# Parallel: pair each source with its reference. Stream so only the test shards
|
| 34 |
+
# are fetched (test shares a config with the large designed/train split).
|
| 35 |
+
sources = load_dataset(REPO, "raw", split="test", streaming=True) # 120 inputs
|
| 36 |
+
references = load_dataset(REPO, "designed", split="test", streaming=True) # 5,640 refs
|
| 37 |
|
| 38 |
+
# the 120 sources are small — collect them for lookup by file_path
|
| 39 |
+
source_by_path = {clip["file_path"]: clip for clip in sources}
|
|
|
|
| 40 |
|
| 41 |
+
# seen/unseen condition per reference (from metadata/test_pairs.csv)
|
| 42 |
pairs_csv = hf_hub_download(REPO, "metadata/test_pairs.csv", repo_type="dataset")
|
| 43 |
+
seen_split = {row["reference"]: row["seen_split"]
|
| 44 |
+
for row in csv.DictReader(open(pairs_csv, encoding="utf-8"))}
|
| 45 |
|
| 46 |
+
for reference in islice(references, 3):
|
| 47 |
+
source = source_by_path[reference["source"]] # `source` column = paired input
|
|
|
|
| 48 |
src_wav = source["audio"]["array"]
|
| 49 |
ref_wav = reference["audio"]["array"]
|
| 50 |
+
print(f" [{seen_split[reference['file_path']]}] "
|
| 51 |
+
f"{reference['source']} -> {reference['file_path']}")
|
| 52 |
# ... compute your voice-conversion metric between src_wav and ref_wav ...
|