From df58db8813e782dd10b4e4dc40f759d36c306d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schw=C3=A4r?= Date: Thu, 5 Nov 2026 22:42:06 +0100 Subject: [PATCH 1/7] Add first version of the LM-SVR experiment, including LM-SSD dataloader --- README.md | 36 ++++ .../TISMIR2024/data_splits/AAT3_LMA_1M_DS.gin | 13 ++ .../TISMIR2024/data_splits/AAT3_LMA_1M_DT.gin | 13 ++ .../TISMIR2024/data_splits/AAT3_LMA_1M_OF.gin | 13 ++ .../TISMIR2024/data_splits/AAT6_LMB_1M_DS.gin | 13 ++ .../TISMIR2024/data_splits/AAT6_LMB_1M_DT.gin | 13 ++ .../TISMIR2024/data_splits/AAT6_LMB_1M_OF.gin | 13 ++ .../TISMIR2024/data_splits/CCT2_LMA_4F_DS.gin | 13 ++ .../TISMIR2024/data_splits/CCT2_LMA_4F_DT.gin | 13 ++ .../TISMIR2024/data_splits/CCT2_LMA_4F_OF.gin | 13 ++ .../TISMIR2024/data_splits/CCT5_LMB_4F_DS.gin | 13 ++ .../TISMIR2024/data_splits/CCT5_LMB_4F_DT.gin | 13 ++ .../TISMIR2024/data_splits/CCT5_LMB_4F_OF.gin | 13 ++ .../TISMIR2024/data_splits/DLT2_LMA_2M_DS.gin | 13 ++ .../TISMIR2024/data_splits/DLT2_LMA_2M_DT.gin | 13 ++ .../TISMIR2024/data_splits/DLT2_LMA_2M_OF.gin | 13 ++ .../TISMIR2024/data_splits/DLT5_LMB_2M_DS.gin | 13 ++ .../TISMIR2024/data_splits/DLT5_LMB_2M_DT.gin | 13 ++ .../TISMIR2024/data_splits/DLT5_LMB_2M_OF.gin | 13 ++ .../TISMIR2024/data_splits/SGT2_LMA_1M_DS.gin | 13 ++ .../TISMIR2024/data_splits/SGT2_LMA_1M_DT.gin | 13 ++ .../TISMIR2024/data_splits/SGT2_LMA_1M_OF.gin | 13 ++ .../TISMIR2024/data_splits/SGT2_LMA_3F_DS.gin | 13 ++ .../TISMIR2024/data_splits/SGT2_LMA_3F_DT.gin | 13 ++ .../TISMIR2024/data_splits/SGT2_LMA_3F_OF.gin | 13 ++ .../TISMIR2024/data_splits/SGT5_LMB_1M_DS.gin | 13 ++ .../TISMIR2024/data_splits/SGT5_LMB_1M_DT.gin | 13 ++ .../TISMIR2024/data_splits/SGT5_LMB_1M_OF.gin | 13 ++ .../TISMIR2024/data_splits/SGT5_LMB_3F_DS.gin | 13 ++ .../TISMIR2024/data_splits/SGT5_LMB_3F_DT.gin | 13 ++ .../TISMIR2024/data_splits/SGT5_LMB_3F_OF.gin | 13 ++ configs/TISMIR2024/lmsvr_base.gin | 57 ++++++ docs/datasets.rst | 4 + experiments/TISMIR2024/lmsvr_baseline.py | 189 ++++++++++++++++++ experiments/TISMIR2024/visualize_baseline.py | 158 +++++++++++++++ libdamp/__init__.py | 2 + libdamp/datasets/__init__.py | 2 + libdamp/datasets/lm_ssd.py | 172 ++++++++++++++++ test/datasets/test_lm_ssd.py | 94 +++++++++ 39 files changed, 1104 insertions(+) create mode 100644 configs/TISMIR2024/data_splits/AAT3_LMA_1M_DS.gin create mode 100644 configs/TISMIR2024/data_splits/AAT3_LMA_1M_DT.gin create mode 100644 configs/TISMIR2024/data_splits/AAT3_LMA_1M_OF.gin create mode 100644 configs/TISMIR2024/data_splits/AAT6_LMB_1M_DS.gin create mode 100644 configs/TISMIR2024/data_splits/AAT6_LMB_1M_DT.gin create mode 100644 configs/TISMIR2024/data_splits/AAT6_LMB_1M_OF.gin create mode 100644 configs/TISMIR2024/data_splits/CCT2_LMA_4F_DS.gin create mode 100644 configs/TISMIR2024/data_splits/CCT2_LMA_4F_DT.gin create mode 100644 configs/TISMIR2024/data_splits/CCT2_LMA_4F_OF.gin create mode 100644 configs/TISMIR2024/data_splits/CCT5_LMB_4F_DS.gin create mode 100644 configs/TISMIR2024/data_splits/CCT5_LMB_4F_DT.gin create mode 100644 configs/TISMIR2024/data_splits/CCT5_LMB_4F_OF.gin create mode 100644 configs/TISMIR2024/data_splits/DLT2_LMA_2M_DS.gin create mode 100644 configs/TISMIR2024/data_splits/DLT2_LMA_2M_DT.gin create mode 100644 configs/TISMIR2024/data_splits/DLT2_LMA_2M_OF.gin create mode 100644 configs/TISMIR2024/data_splits/DLT5_LMB_2M_DS.gin create mode 100644 configs/TISMIR2024/data_splits/DLT5_LMB_2M_DT.gin create mode 100644 configs/TISMIR2024/data_splits/DLT5_LMB_2M_OF.gin create mode 100644 configs/TISMIR2024/data_splits/SGT2_LMA_1M_DS.gin create mode 100644 configs/TISMIR2024/data_splits/SGT2_LMA_1M_DT.gin create mode 100644 configs/TISMIR2024/data_splits/SGT2_LMA_1M_OF.gin create mode 100644 configs/TISMIR2024/data_splits/SGT2_LMA_3F_DS.gin create mode 100644 configs/TISMIR2024/data_splits/SGT2_LMA_3F_DT.gin create mode 100644 configs/TISMIR2024/data_splits/SGT2_LMA_3F_OF.gin create mode 100644 configs/TISMIR2024/data_splits/SGT5_LMB_1M_DS.gin create mode 100644 configs/TISMIR2024/data_splits/SGT5_LMB_1M_DT.gin create mode 100644 configs/TISMIR2024/data_splits/SGT5_LMB_1M_OF.gin create mode 100644 configs/TISMIR2024/data_splits/SGT5_LMB_3F_DS.gin create mode 100644 configs/TISMIR2024/data_splits/SGT5_LMB_3F_DT.gin create mode 100644 configs/TISMIR2024/data_splits/SGT5_LMB_3F_OF.gin create mode 100644 configs/TISMIR2024/lmsvr_base.gin create mode 100644 experiments/TISMIR2024/lmsvr_baseline.py create mode 100644 experiments/TISMIR2024/visualize_baseline.py create mode 100644 libdamp/datasets/lm_ssd.py create mode 100644 test/datasets/test_lm_ssd.py diff --git a/README.md b/README.md index 6a46238..bd9fd10 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Framework for experiments with differentiable audio and music processing (DDSP) - [Project structure](#project-structure) - [Experiments](#experiments) - [ICASSP2026 (Wind Instrument Synthesis with Pulsetables)](#icassp2026-wind-instrument-synthesis-with-pulsetables) + - [TISMIR2024 (Larynx Microphone Singing Voice Reconstruction)](#tismir2024-larynx-microphone-singing-voice-reconstruction) - [Vocal Revolutions](#vocal-revolutions) - [Development](#development) - [Running tests](#running-tests) @@ -103,6 +104,41 @@ To reproduce results: 4. Run the experiment, for example with `uv run scripts/run.py --config configs/ICASSP2026/pulsewave_base.gin configs/ICASSP2026/instr/01_tp.gin configs/ICASSP2026/mode/pulse_4.gin` for training with trumpet voice 1 and using the pulsetable method with 4 pulses (see the configs folder for other options). 5. Trained models are stored in the `results` folder. You can load them and play around with them using the notebook `notebooks/ICASSP2026/explore_model.ipynb`. +### TISMIR2024 (Larynx Microphone Singing Voice Reconstruction) + +The files in `experiments/TISMIR2024`, `configs/TISMIR2024`, and `libdamp/datasets/lm_ssd.py` reimplement the baseline system described in Section 5 of: + +``` +@article{SchwaerKFRSM24_LarynxMicSVR_TISMIR, + author = {Simon Schw{\"a}r and Michael Krause and Michael Fast and Sebastian Rosenzweig and Frank Scherbaum and Meinard M{\"u}ller}, + title = {A Dataset of Larynx Microphone Recordings for Singing Voice Reconstruction}, + journal = {Transaction of the International Society for Music Information Retrieval ({TISMIR})}, + year = {2024}, + volume = {7}, + number = {1}, + pages = {30--43}, + doi = {10.5334/tismir.166} +} +``` + +Note that this implementation is NOT the same as the one used for the experiments in the paper. In particular, the following differences may lead to slightly different results: +* The Convolutional Network architecture consists of a single stack of 3 convolutional layers + (no residual/skip connections). +* Network outputs are mapped to DSP magnitude parameters with a scaled-sigmoid (`exp_sigmoid`, bias -3, exponent log(10)), following the convention used in the ICASSP2026 experiment. +* Training excerpts are selected at random from each take, and are filtered to skip near-silent excerpts. + + +To reproduce results: +1. Download the [LM-SSD](https://zenodo.org/records/20287765) dataset and extract it. +2. Update the `dataset_path` variable in `configs/TISMIR2024/lmsvr_base.gin` to point at the dataset's `audio` folder. +3. Run the experiment, for example with `uv run scripts/run.py --config configs/TISMIR2024/lmsvr_base.gin configs/TISMIR2024/data_splits/AAT3_LMA_1M_DT.gin` to train on singer 1M with microphone LM-A, holding out take 3 of song "AA" with the "Different Take" (DT) split. +`configs/TISMIR2024/data_splits` contains configs named `___.gin`, one for each (experiment, LM type, singer, split) combination derived from the dataset's own `train_test_splits.csv` (Section 6 of the paper): + * **OF:** overfitting, the held-out take is also included in training + * **DT:** different take, the one evaluation take is excluded from an otherwise identical training set + * **DS:** different song, all takes of the evaluation take's song are excluded. +4. Trained models are stored in the `results` folder using a descriptive name. +5. For a quick sanity check of a trained model, run `uv run experiments/TISMIR2024/visualize_baseline.py ` (e.g. `AAT3_LMA_1M_DT`, needs the `notebooks` extra for `matplotlib`). It loads that experiment's best checkpoint, runs it on an excerpt of the held-out test take, and saves a plot of the signal at each stage of the signal flow next to the CM reference (similar to Fig. 5 in the paper). + ### Vocal Revolutions The files in `experiments/VocalRevolutions`, `configs/VocalRevolutions`, and `notebooks/VocalRevolutions` are accompanying an art project in collaboration with [Tim Otto Roth](https://imachination.net/) and his [Heaven's Carousel](https://vimeo.com/1102923991). diff --git a/configs/TISMIR2024/data_splits/AAT3_LMA_1M_DS.gin b/configs/TISMIR2024/data_splits/AAT3_LMA_1M_DS.gin new file mode 100644 index 0000000..5f0e7b0 --- /dev/null +++ b/configs/TISMIR2024/data_splits/AAT3_LMA_1M_DS.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item AA T3, microphone LM-A, singer 1M, "DS" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DS column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "AAT3_LMA_1M_DS_{date}" + +train/LMSSDDataset.selection = r"(_TS_LM_C0_1M_T2\.wav$|_TS_LM_C0_1M_T3\.wav$|_YF_LM_C0_1M_T2\.wav$|_YF_LM_C0_1M_T3\.wav$)" +val/LMSSDDataset.selection = r"_AA_LM_C0_1M_T3\.wav$" diff --git a/configs/TISMIR2024/data_splits/AAT3_LMA_1M_DT.gin b/configs/TISMIR2024/data_splits/AAT3_LMA_1M_DT.gin new file mode 100644 index 0000000..e88799c --- /dev/null +++ b/configs/TISMIR2024/data_splits/AAT3_LMA_1M_DT.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item AA T3, microphone LM-A, singer 1M, "DT" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DT column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "AAT3_LMA_1M_DT_{date}" + +train/LMSSDDataset.selection = r"(_AA_LM_C0_1M_T2\.wav$|_TS_LM_C0_1M_T2\.wav$|_TS_LM_C0_1M_T3\.wav$|_YF_LM_C0_1M_T2\.wav$|_YF_LM_C0_1M_T3\.wav$)" +val/LMSSDDataset.selection = r"_AA_LM_C0_1M_T3\.wav$" diff --git a/configs/TISMIR2024/data_splits/AAT3_LMA_1M_OF.gin b/configs/TISMIR2024/data_splits/AAT3_LMA_1M_OF.gin new file mode 100644 index 0000000..4ffddf8 --- /dev/null +++ b/configs/TISMIR2024/data_splits/AAT3_LMA_1M_OF.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item AA T3, microphone LM-A, singer 1M, "OF" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (OF column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "AAT3_LMA_1M_OF_{date}" + +train/LMSSDDataset.selection = r"(_AA_LM_C0_1M_T2\.wav$|_AA_LM_C0_1M_T3\.wav$|_TS_LM_C0_1M_T2\.wav$|_TS_LM_C0_1M_T3\.wav$|_YF_LM_C0_1M_T2\.wav$|_YF_LM_C0_1M_T3\.wav$)" +val/LMSSDDataset.selection = r"_AA_LM_C0_1M_T3\.wav$" diff --git a/configs/TISMIR2024/data_splits/AAT6_LMB_1M_DS.gin b/configs/TISMIR2024/data_splits/AAT6_LMB_1M_DS.gin new file mode 100644 index 0000000..049646f --- /dev/null +++ b/configs/TISMIR2024/data_splits/AAT6_LMB_1M_DS.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item AA T6, microphone LM-B, singer 1M, "DS" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DS column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "AAT6_LMB_1M_DS_{date}" + +train/LMSSDDataset.selection = r"(_TS_LM_C0_1M_T5\.wav$|_TS_LM_C0_1M_T6\.wav$|_YF_LM_C0_1M_T5\.wav$|_YF_LM_C0_1M_T6\.wav$)" +val/LMSSDDataset.selection = r"_AA_LM_C0_1M_T6\.wav$" diff --git a/configs/TISMIR2024/data_splits/AAT6_LMB_1M_DT.gin b/configs/TISMIR2024/data_splits/AAT6_LMB_1M_DT.gin new file mode 100644 index 0000000..0ce19d2 --- /dev/null +++ b/configs/TISMIR2024/data_splits/AAT6_LMB_1M_DT.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item AA T6, microphone LM-B, singer 1M, "DT" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DT column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "AAT6_LMB_1M_DT_{date}" + +train/LMSSDDataset.selection = r"(_AA_LM_C0_1M_T5\.wav$|_TS_LM_C0_1M_T5\.wav$|_TS_LM_C0_1M_T6\.wav$|_YF_LM_C0_1M_T5\.wav$|_YF_LM_C0_1M_T6\.wav$)" +val/LMSSDDataset.selection = r"_AA_LM_C0_1M_T6\.wav$" diff --git a/configs/TISMIR2024/data_splits/AAT6_LMB_1M_OF.gin b/configs/TISMIR2024/data_splits/AAT6_LMB_1M_OF.gin new file mode 100644 index 0000000..5beda0b --- /dev/null +++ b/configs/TISMIR2024/data_splits/AAT6_LMB_1M_OF.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item AA T6, microphone LM-B, singer 1M, "OF" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (OF column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "AAT6_LMB_1M_OF_{date}" + +train/LMSSDDataset.selection = r"(_AA_LM_C0_1M_T5\.wav$|_AA_LM_C0_1M_T6\.wav$|_TS_LM_C0_1M_T5\.wav$|_TS_LM_C0_1M_T6\.wav$|_YF_LM_C0_1M_T5\.wav$|_YF_LM_C0_1M_T6\.wav$)" +val/LMSSDDataset.selection = r"_AA_LM_C0_1M_T6\.wav$" diff --git a/configs/TISMIR2024/data_splits/CCT2_LMA_4F_DS.gin b/configs/TISMIR2024/data_splits/CCT2_LMA_4F_DS.gin new file mode 100644 index 0000000..e409e05 --- /dev/null +++ b/configs/TISMIR2024/data_splits/CCT2_LMA_4F_DS.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item CC T2, microphone LM-A, singer 4F, "DS" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DS column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "CCT2_LMA_4F_DS_{date}" + +train/LMSSDDataset.selection = r"(_BT_LM_C0_4F_T2\.wav$|_BT_LM_C0_4F_T3\.wav$|_LL_LM_C0_4F_T2\.wav$|_LL_LM_C0_4F_T3\.wav$)" +val/LMSSDDataset.selection = r"_CC_LM_C0_4F_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/CCT2_LMA_4F_DT.gin b/configs/TISMIR2024/data_splits/CCT2_LMA_4F_DT.gin new file mode 100644 index 0000000..7409a1f --- /dev/null +++ b/configs/TISMIR2024/data_splits/CCT2_LMA_4F_DT.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item CC T2, microphone LM-A, singer 4F, "DT" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DT column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "CCT2_LMA_4F_DT_{date}" + +train/LMSSDDataset.selection = r"(_CC_LM_C0_4F_T3\.wav$|_BT_LM_C0_4F_T2\.wav$|_BT_LM_C0_4F_T3\.wav$|_LL_LM_C0_4F_T2\.wav$|_LL_LM_C0_4F_T3\.wav$)" +val/LMSSDDataset.selection = r"_CC_LM_C0_4F_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/CCT2_LMA_4F_OF.gin b/configs/TISMIR2024/data_splits/CCT2_LMA_4F_OF.gin new file mode 100644 index 0000000..bf05912 --- /dev/null +++ b/configs/TISMIR2024/data_splits/CCT2_LMA_4F_OF.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item CC T2, microphone LM-A, singer 4F, "OF" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (OF column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "CCT2_LMA_4F_OF_{date}" + +train/LMSSDDataset.selection = r"(_CC_LM_C0_4F_T2\.wav$|_CC_LM_C0_4F_T3\.wav$|_BT_LM_C0_4F_T2\.wav$|_BT_LM_C0_4F_T3\.wav$|_LL_LM_C0_4F_T2\.wav$|_LL_LM_C0_4F_T3\.wav$)" +val/LMSSDDataset.selection = r"_CC_LM_C0_4F_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/CCT5_LMB_4F_DS.gin b/configs/TISMIR2024/data_splits/CCT5_LMB_4F_DS.gin new file mode 100644 index 0000000..d6f1fe3 --- /dev/null +++ b/configs/TISMIR2024/data_splits/CCT5_LMB_4F_DS.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item CC T5, microphone LM-B, singer 4F, "DS" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DS column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "CCT5_LMB_4F_DS_{date}" + +train/LMSSDDataset.selection = r"(_BT_LM_C0_4F_T5\.wav$|_BT_LM_C0_4F_T6\.wav$|_LL_LM_C0_4F_T5\.wav$|_LL_LM_C0_4F_T6\.wav$)" +val/LMSSDDataset.selection = r"_CC_LM_C0_4F_T5\.wav$" diff --git a/configs/TISMIR2024/data_splits/CCT5_LMB_4F_DT.gin b/configs/TISMIR2024/data_splits/CCT5_LMB_4F_DT.gin new file mode 100644 index 0000000..63d1172 --- /dev/null +++ b/configs/TISMIR2024/data_splits/CCT5_LMB_4F_DT.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item CC T5, microphone LM-B, singer 4F, "DT" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DT column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "CCT5_LMB_4F_DT_{date}" + +train/LMSSDDataset.selection = r"(_CC_LM_C0_4F_T6\.wav$|_BT_LM_C0_4F_T5\.wav$|_BT_LM_C0_4F_T6\.wav$|_LL_LM_C0_4F_T5\.wav$|_LL_LM_C0_4F_T6\.wav$)" +val/LMSSDDataset.selection = r"_CC_LM_C0_4F_T5\.wav$" diff --git a/configs/TISMIR2024/data_splits/CCT5_LMB_4F_OF.gin b/configs/TISMIR2024/data_splits/CCT5_LMB_4F_OF.gin new file mode 100644 index 0000000..ab71abe --- /dev/null +++ b/configs/TISMIR2024/data_splits/CCT5_LMB_4F_OF.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item CC T5, microphone LM-B, singer 4F, "OF" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (OF column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "CCT5_LMB_4F_OF_{date}" + +train/LMSSDDataset.selection = r"(_CC_LM_C0_4F_T5\.wav$|_CC_LM_C0_4F_T6\.wav$|_BT_LM_C0_4F_T5\.wav$|_BT_LM_C0_4F_T6\.wav$|_LL_LM_C0_4F_T5\.wav$|_LL_LM_C0_4F_T6\.wav$)" +val/LMSSDDataset.selection = r"_CC_LM_C0_4F_T5\.wav$" diff --git a/configs/TISMIR2024/data_splits/DLT2_LMA_2M_DS.gin b/configs/TISMIR2024/data_splits/DLT2_LMA_2M_DS.gin new file mode 100644 index 0000000..f349499 --- /dev/null +++ b/configs/TISMIR2024/data_splits/DLT2_LMA_2M_DS.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item DL T2, microphone LM-A, singer 2M, "DS" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DS column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "DLT2_LMA_2M_DS_{date}" + +train/LMSSDDataset.selection = r"(_BB_LM_C0_2M_T2\.wav$|_BB_LM_C0_2M_T3\.wav$|_NB_LM_C0_2M_T2\.wav$|_NB_LM_C0_2M_T3\.wav$)" +val/LMSSDDataset.selection = r"_DL_LM_C0_2M_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/DLT2_LMA_2M_DT.gin b/configs/TISMIR2024/data_splits/DLT2_LMA_2M_DT.gin new file mode 100644 index 0000000..4439af1 --- /dev/null +++ b/configs/TISMIR2024/data_splits/DLT2_LMA_2M_DT.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item DL T2, microphone LM-A, singer 2M, "DT" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DT column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "DLT2_LMA_2M_DT_{date}" + +train/LMSSDDataset.selection = r"(_DL_LM_C0_2M_T3\.wav$|_BB_LM_C0_2M_T2\.wav$|_BB_LM_C0_2M_T3\.wav$|_NB_LM_C0_2M_T2\.wav$|_NB_LM_C0_2M_T3\.wav$)" +val/LMSSDDataset.selection = r"_DL_LM_C0_2M_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/DLT2_LMA_2M_OF.gin b/configs/TISMIR2024/data_splits/DLT2_LMA_2M_OF.gin new file mode 100644 index 0000000..be1cc98 --- /dev/null +++ b/configs/TISMIR2024/data_splits/DLT2_LMA_2M_OF.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item DL T2, microphone LM-A, singer 2M, "OF" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (OF column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "DLT2_LMA_2M_OF_{date}" + +train/LMSSDDataset.selection = r"(_DL_LM_C0_2M_T2\.wav$|_DL_LM_C0_2M_T3\.wav$|_BB_LM_C0_2M_T2\.wav$|_BB_LM_C0_2M_T3\.wav$|_NB_LM_C0_2M_T2\.wav$|_NB_LM_C0_2M_T3\.wav$)" +val/LMSSDDataset.selection = r"_DL_LM_C0_2M_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/DLT5_LMB_2M_DS.gin b/configs/TISMIR2024/data_splits/DLT5_LMB_2M_DS.gin new file mode 100644 index 0000000..9d71a0b --- /dev/null +++ b/configs/TISMIR2024/data_splits/DLT5_LMB_2M_DS.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item DL T5, microphone LM-B, singer 2M, "DS" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DS column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "DLT5_LMB_2M_DS_{date}" + +train/LMSSDDataset.selection = r"(_BB_LM_C0_2M_T5\.wav$|_BB_LM_C0_2M_T6\.wav$|_NB_LM_C0_2M_T5\.wav$|_NB_LM_C0_2M_T6\.wav$)" +val/LMSSDDataset.selection = r"_DL_LM_C0_2M_T5\.wav$" diff --git a/configs/TISMIR2024/data_splits/DLT5_LMB_2M_DT.gin b/configs/TISMIR2024/data_splits/DLT5_LMB_2M_DT.gin new file mode 100644 index 0000000..a976d1a --- /dev/null +++ b/configs/TISMIR2024/data_splits/DLT5_LMB_2M_DT.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item DL T5, microphone LM-B, singer 2M, "DT" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DT column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "DLT5_LMB_2M_DT_{date}" + +train/LMSSDDataset.selection = r"(_DL_LM_C0_2M_T6\.wav$|_BB_LM_C0_2M_T5\.wav$|_BB_LM_C0_2M_T6\.wav$|_NB_LM_C0_2M_T5\.wav$|_NB_LM_C0_2M_T6\.wav$)" +val/LMSSDDataset.selection = r"_DL_LM_C0_2M_T5\.wav$" diff --git a/configs/TISMIR2024/data_splits/DLT5_LMB_2M_OF.gin b/configs/TISMIR2024/data_splits/DLT5_LMB_2M_OF.gin new file mode 100644 index 0000000..a69761f --- /dev/null +++ b/configs/TISMIR2024/data_splits/DLT5_LMB_2M_OF.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item DL T5, microphone LM-B, singer 2M, "OF" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (OF column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "DLT5_LMB_2M_OF_{date}" + +train/LMSSDDataset.selection = r"(_DL_LM_C0_2M_T5\.wav$|_DL_LM_C0_2M_T6\.wav$|_BB_LM_C0_2M_T5\.wav$|_BB_LM_C0_2M_T6\.wav$|_NB_LM_C0_2M_T5\.wav$|_NB_LM_C0_2M_T6\.wav$)" +val/LMSSDDataset.selection = r"_DL_LM_C0_2M_T5\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT2_LMA_1M_DS.gin b/configs/TISMIR2024/data_splits/SGT2_LMA_1M_DS.gin new file mode 100644 index 0000000..56b5415 --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT2_LMA_1M_DS.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T2, microphone LM-A, singer 1M, "DS" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DS column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT2_LMA_1M_DS_{date}" + +train/LMSSDDataset.selection = r"(_OC_LM_C0_1M_T2\.wav$|_OC_LM_C0_1M_T3\.wav$|_PL_LM_C0_1M_T2\.wav$|_PL_LM_C0_1M_T3\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_1M_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT2_LMA_1M_DT.gin b/configs/TISMIR2024/data_splits/SGT2_LMA_1M_DT.gin new file mode 100644 index 0000000..cf57438 --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT2_LMA_1M_DT.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T2, microphone LM-A, singer 1M, "DT" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DT column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT2_LMA_1M_DT_{date}" + +train/LMSSDDataset.selection = r"(_SG_LM_C0_1M_T3\.wav$|_OC_LM_C0_1M_T2\.wav$|_OC_LM_C0_1M_T3\.wav$|_PL_LM_C0_1M_T2\.wav$|_PL_LM_C0_1M_T3\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_1M_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT2_LMA_1M_OF.gin b/configs/TISMIR2024/data_splits/SGT2_LMA_1M_OF.gin new file mode 100644 index 0000000..1943777 --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT2_LMA_1M_OF.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T2, microphone LM-A, singer 1M, "OF" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (OF column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT2_LMA_1M_OF_{date}" + +train/LMSSDDataset.selection = r"(_SG_LM_C0_1M_T2\.wav$|_SG_LM_C0_1M_T3\.wav$|_OC_LM_C0_1M_T2\.wav$|_OC_LM_C0_1M_T3\.wav$|_PL_LM_C0_1M_T2\.wav$|_PL_LM_C0_1M_T3\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_1M_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT2_LMA_3F_DS.gin b/configs/TISMIR2024/data_splits/SGT2_LMA_3F_DS.gin new file mode 100644 index 0000000..d77ea00 --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT2_LMA_3F_DS.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T2, microphone LM-A, singer 3F, "DS" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DS column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT2_LMA_3F_DS_{date}" + +train/LMSSDDataset.selection = r"(_OC_LM_C0_3F_T2\.wav$|_OC_LM_C0_3F_T3\.wav$|_PL_LM_C0_3F_T2\.wav$|_PL_LM_C0_3F_T3\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_3F_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT2_LMA_3F_DT.gin b/configs/TISMIR2024/data_splits/SGT2_LMA_3F_DT.gin new file mode 100644 index 0000000..814edef --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT2_LMA_3F_DT.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T2, microphone LM-A, singer 3F, "DT" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DT column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT2_LMA_3F_DT_{date}" + +train/LMSSDDataset.selection = r"(_SG_LM_C0_3F_T3\.wav$|_OC_LM_C0_3F_T2\.wav$|_OC_LM_C0_3F_T3\.wav$|_PL_LM_C0_3F_T2\.wav$|_PL_LM_C0_3F_T3\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_3F_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT2_LMA_3F_OF.gin b/configs/TISMIR2024/data_splits/SGT2_LMA_3F_OF.gin new file mode 100644 index 0000000..8604abc --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT2_LMA_3F_OF.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T2, microphone LM-A, singer 3F, "OF" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (OF column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT2_LMA_3F_OF_{date}" + +train/LMSSDDataset.selection = r"(_SG_LM_C0_3F_T2\.wav$|_SG_LM_C0_3F_T3\.wav$|_OC_LM_C0_3F_T2\.wav$|_OC_LM_C0_3F_T3\.wav$|_PL_LM_C0_3F_T2\.wav$|_PL_LM_C0_3F_T3\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_3F_T2\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT5_LMB_1M_DS.gin b/configs/TISMIR2024/data_splits/SGT5_LMB_1M_DS.gin new file mode 100644 index 0000000..f981255 --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT5_LMB_1M_DS.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T5, microphone LM-B, singer 1M, "DS" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DS column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT5_LMB_1M_DS_{date}" + +train/LMSSDDataset.selection = r"(_OC_LM_C0_1M_T5\.wav$|_OC_LM_C0_1M_T6\.wav$|_PL_LM_C0_1M_T5\.wav$|_PL_LM_C0_1M_T6\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_1M_T5\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT5_LMB_1M_DT.gin b/configs/TISMIR2024/data_splits/SGT5_LMB_1M_DT.gin new file mode 100644 index 0000000..53b662d --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT5_LMB_1M_DT.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T5, microphone LM-B, singer 1M, "DT" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DT column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT5_LMB_1M_DT_{date}" + +train/LMSSDDataset.selection = r"(_SG_LM_C0_1M_T6\.wav$|_OC_LM_C0_1M_T5\.wav$|_OC_LM_C0_1M_T6\.wav$|_PL_LM_C0_1M_T5\.wav$|_PL_LM_C0_1M_T6\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_1M_T5\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT5_LMB_1M_OF.gin b/configs/TISMIR2024/data_splits/SGT5_LMB_1M_OF.gin new file mode 100644 index 0000000..dd855ff --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT5_LMB_1M_OF.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T5, microphone LM-B, singer 1M, "OF" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (OF column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT5_LMB_1M_OF_{date}" + +train/LMSSDDataset.selection = r"(_SG_LM_C0_1M_T5\.wav$|_SG_LM_C0_1M_T6\.wav$|_OC_LM_C0_1M_T5\.wav$|_OC_LM_C0_1M_T6\.wav$|_PL_LM_C0_1M_T5\.wav$|_PL_LM_C0_1M_T6\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_1M_T5\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT5_LMB_3F_DS.gin b/configs/TISMIR2024/data_splits/SGT5_LMB_3F_DS.gin new file mode 100644 index 0000000..a49108d --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT5_LMB_3F_DS.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T5, microphone LM-B, singer 3F, "DS" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DS column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT5_LMB_3F_DS_{date}" + +train/LMSSDDataset.selection = r"(_OC_LM_C0_3F_T5\.wav$|_OC_LM_C0_3F_T6\.wav$|_PL_LM_C0_3F_T5\.wav$|_PL_LM_C0_3F_T6\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_3F_T5\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT5_LMB_3F_DT.gin b/configs/TISMIR2024/data_splits/SGT5_LMB_3F_DT.gin new file mode 100644 index 0000000..40a33ed --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT5_LMB_3F_DT.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T5, microphone LM-B, singer 3F, "DT" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (DT column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT5_LMB_3F_DT_{date}" + +train/LMSSDDataset.selection = r"(_SG_LM_C0_3F_T6\.wav$|_OC_LM_C0_3F_T5\.wav$|_OC_LM_C0_3F_T6\.wav$|_PL_LM_C0_3F_T5\.wav$|_PL_LM_C0_3F_T6\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_3F_T5\.wav$" diff --git a/configs/TISMIR2024/data_splits/SGT5_LMB_3F_OF.gin b/configs/TISMIR2024/data_splits/SGT5_LMB_3F_OF.gin new file mode 100644 index 0000000..963f7ca --- /dev/null +++ b/configs/TISMIR2024/data_splits/SGT5_LMB_3F_OF.gin @@ -0,0 +1,13 @@ +include 'configs/TISMIR2024/lmsvr_base.gin' + +######## +# Held-out test item SG T5, microphone LM-B, singer 3F, "OF" split. +# Train/val takes taken verbatim from the dataset's own `train_test_splits.csv` (OF column). +######## + +# encode this config's own ID into the results folder name, so a trained checkpoint can later +# be found again from the ID alone (see `experiments/TISMIR2024/visualize_baseline.py`) +Experiment.name = "SGT5_LMB_3F_OF_{date}" + +train/LMSSDDataset.selection = r"(_SG_LM_C0_3F_T5\.wav$|_SG_LM_C0_3F_T6\.wav$|_OC_LM_C0_3F_T5\.wav$|_OC_LM_C0_3F_T6\.wav$|_PL_LM_C0_3F_T5\.wav$|_PL_LM_C0_3F_T6\.wav$)" +val/LMSSDDataset.selection = r"_SG_LM_C0_3F_T5\.wav$" diff --git a/configs/TISMIR2024/lmsvr_base.gin b/configs/TISMIR2024/lmsvr_base.gin new file mode 100644 index 0000000..be2edde --- /dev/null +++ b/configs/TISMIR2024/lmsvr_base.gin @@ -0,0 +1,57 @@ +include 'configs/base.gin' + +# Override Experiment defaults +Experiment.name = "tismir2024_lmsvr_{date}" +Experiment.early_stopping = False +Experiment.save_best_n_ckpts = 1 +Experiment.max_epochs = 40 +Experiment.batch_size = 32 +Experiment.limit_val_batches = 1.0 +Experiment.shuffle_data = True + +sampling_rate = 16000. +frame_len = 320 # 20 ms +excerpt_len = 64000 # 4 s + +# Load and configure the specific experiment +import experiments.TISMIR2024.lmsvr_baseline + +libdamp.experiment = @LMSVRBaselineExperiment() + +LMSVRBaselineExperiment.fs = %sampling_rate +LMSVRBaselineExperiment.frame_len = %frame_len + +LMSVRBaselineExperiment.n_fft_mel = 2048 +LMSVRBaselineExperiment.n_mels = 64 +LMSVRBaselineExperiment.f_min_mel = 50.0 +LMSVRBaselineExperiment.f_max_mel = 8000.0 + +LMSVRBaselineExperiment.filt_len = 320 +LMSVRBaselineExperiment.num_bands_ti = 64 +LMSVRBaselineExperiment.num_bands_tv = 64 +LMSVRBaselineExperiment.num_bands_noise = 10 + +LMSVRBaselineExperiment.model_size_control = 128 + +LMSVRBaselineExperiment.learning_rate = 1e-3 + +LMSVRBaselineExperiment.loss_fn = @MSSLoss() +MSSLoss.w_mag = 1.0 +MSSLoss.w_log = 1.0 +MSSLoss.fft_sizes = (2048, 1024, 512, 256, 128, 64) +MSSLoss.win = "hann" + +dataset_path = "~/Desktop/datasets/lm-ssd/LM-SSD/audio" + +# The exact data splits are defined in the separate config files in the subfolder "data_splits" +libdamp.train_dataset = @train/LMSSDDataset() +libdamp.val_dataset = @val/LMSSDDataset() + +LMSSDDataset.target_fs = %sampling_rate +LMSSDDataset.excerpt_len = %excerpt_len +LMSSDDataset.random_seed = 42 + +train/LMSSDDataset.path = %dataset_path +train/LMSSDDataset.num_excerpts = 1000 # per file +val/LMSSDDataset.path = %dataset_path +val/LMSSDDataset.num_excerpts = 100 diff --git a/docs/datasets.rst b/docs/datasets.rst index 352124a..a55fa75 100644 --- a/docs/datasets.rst +++ b/docs/datasets.rst @@ -9,6 +9,10 @@ Datasets :members: :show-inheritance: +.. automodule:: libdamp.datasets.lm_ssd + :members: + :show-inheritance: + .. automodule:: libdamp.datasets.medleydb :members: :show-inheritance: diff --git a/experiments/TISMIR2024/lmsvr_baseline.py b/experiments/TISMIR2024/lmsvr_baseline.py new file mode 100644 index 0000000..d84e7e8 --- /dev/null +++ b/experiments/TISMIR2024/lmsvr_baseline.py @@ -0,0 +1,189 @@ +"""Baseline system for larynx microphone singing voice reconstruction (LM-SVR). + +Reimplements the baseline described in Section 5 of Schwär et al., "A Dataset of Larynx +Microphone Recordings for Singing Voice Reconstruction," TISMIR 7(1), 2024 +(https://doi.org/10.5334/tismir.166). + +A control network estimates parameters for a chain of differentiable DSP blocks that +transform the larynx microphone (LM) signal towards the close-up microphone (CM) signal: a +time-invariant FIR filter (EQ, constant over the duration of the input but still estimated +from it), peak normalization, a noise synthesizer (for fricatives), and a time-varying FIR +filter (vocal tract / formants) - matching the signal flow in Figure 5 of the paper. +""" + +import math + +import gin +import torch +import torchaudio as taudio + +import libdamp + + +def peak_norm(x, eps=1e-7): + """Normalize each signal in the batch to unit peak amplitude. + """ + peak = x.abs().amax(dim=-1, keepdim=True) + return x / (peak + eps) + + +@gin.configurable +class LMSVRBaselineExperiment(libdamp.Experiment): + """Baseline system for larynx microphone singing voice reconstruction (LM-SVR).""" + + def __init__( + self, + fs=16000.0, + frame_len=320, + filt_len=320, + n_fft_mel=2048, + n_mels=64, + f_min_mel=50.0, + f_max_mel=8000.0, + num_bands_ti=64, + num_bands_tv=64, + num_bands_noise=10, + model_size_control=128, + learning_rate=1e-3, + loss_fn=None, + **kwargs, + ): + """Baseline system for larynx microphone singing voice reconstruction (LM-SVR). + + Parameters + ---------- + fs : float + Sampling rate in Hz (default: 16000.0). + frame_len : int + Frame length in samples, both for the mel input to the control network and + for the time-varying DDSP blocks (default: 320). + filt_len : int + FIR filter length in samples, shared by the TI filter, TV filter, and noise + synthesizer (default: 320). + n_fft_mel : int + FFT/window size of the Hann-windowed STFT used for the mel input to the control + network (default: 2048). + n_mels : int + Number of mel bands for the control network's input (default: 64). + f_min_mel : float + Lowest frequency of the mel input (default: 50.0). + f_max_mel : float or None + Highest frequency of the mel input (default: 8000.0). + num_bands_ti : int + Number of linearly spaced magnitude bands for the time-invariant FIR filter (default: 64). + This filter is constant over the duration of the input signal, but its magnitudes are still estimated + from that input (by averaging the control network's per-frame features over time). + num_bands_tv : int + Number of linearly spaced magnitude bands for the time-varying FIR filter (default: 64). + num_bands_noise : int + Number of magnitude bands for the noise synthesizer's filter (default: 10). + model_size_control : int + Feature dimensionality of the CNN output and recurrent hidden state. + learning_rate : float + loss_fn : torch.nn.Module or None + Loss function comparing predicted and reference CM signal. + """ + super().__init__(**kwargs) + + self.fs = fs + self.frame_len = frame_len + self.filt_len = filt_len + + self.learning_rate = learning_rate + self.loss_fn = loss_fn if loss_fn is not None else libdamp.MSSLoss() + + f_max_mel = f_max_mel if f_max_mel is not None else fs / 2 + self.mel_transform = taudio.transforms.MelSpectrogram( + sample_rate=fs, + n_fft=n_fft_mel, + hop_length=frame_len, + f_min=f_min_mel, + f_max=f_max_mel, + n_mels=n_mels, + center=False, + pad=(n_fft_mel - frame_len) // 2, + ) + + self.control_cnn = libdamp.ConvStack(n_mels, model_size_control) + self.control_rnn = libdamp.BiLSTM(model_size_control, model_size_control // 2) + + self.ti_head = torch.nn.Linear(model_size_control, num_bands_ti) + self.noise_head = torch.nn.Linear(model_size_control, num_bands_noise) + self.tv_head = torch.nn.Linear(model_size_control, num_bands_tv) + + self.ti_filter = libdamp.processors.TVMagnitudesFilter( + frame_len, filt_len, fs, center_freqs=torch.linspace(0, fs / 2, num_bands_ti), filter_phase="linear" + ) + self.tv_filter = libdamp.processors.TVMagnitudesFilter( + frame_len, filt_len, fs, center_freqs=torch.linspace(0, fs / 2, num_bands_tv), filter_phase="linear" + ) + + self.noise_synth = libdamp.generators.SimpleFilteredNoise( + frame_len, filt_len, fs, torch.linspace(0, fs / 2, num_bands_noise) + ) + + def estimate_params(self, x): + """Estimate TI filter, TV filter, and noise synthesizer magnitudes from the LM input. + """ + mel = torch.log(1 + self.mel_transform(x.unsqueeze(-2))) + feat = self.control_cnn(mel) + feat = self.control_rnn(feat) + + ti_mag = libdamp.exp_sigmoid(self.ti_head(feat.mean(dim=1, keepdim=True)) - 3, exp=math.log(10.0)) + noise_mag = libdamp.exp_sigmoid(self.noise_head(feat) - 3, exp=math.log(10.0)) + tv_mag = libdamp.exp_sigmoid(self.tv_head(feat) - 3, exp=math.log(10.0)) + + return ti_mag, tv_mag, noise_mag + + def forward(self, x, return_intermediates=False): + """Forward pass implementation. + """ + ti_mag, tv_mag, noise_mag = self.estimate_params(x) + + self.ti_filter.clear() + self.ti_filter.update(ti_mag) + y_ti = self.ti_filter.process(x) + + y_norm = self.peak_norm(y_ti) + + noise = self.noise_synth.generate(noise_mag) + y_noisy = y_norm + noise + + self.tv_filter.clear() + self.tv_filter.update(tv_mag) + y_hat = self.tv_filter.process(y_noisy) + + if return_intermediates: + return y_hat, { + "x_lm": x, + "ti_filtered": y_ti, + "peak_normed": y_norm, + "noise": noise, + "noisy": y_noisy, + "y_hat": y_hat, + } + + return y_hat + + def training_step(self, batch, _): + x_lm, x_cm = batch + + y_hat = self(x_lm) + loss = self.loss_fn(x_cm, y_hat).mean() + + self.log("train_loss", loss, on_step=True, on_epoch=True, prog_bar=True, logger=True) + + return loss + + def validation_step(self, batch, _): + x_lm, x_cm = batch + + y_hat = self(x_lm) + loss = self.loss_fn(x_cm, y_hat).mean() + + self.log("val_loss", loss, on_step=False, on_epoch=True, prog_bar=True, logger=True) + + return loss + + def configure_optimizers(self): + return torch.optim.Adam(self.parameters(), lr=self.learning_rate) diff --git a/experiments/TISMIR2024/visualize_baseline.py b/experiments/TISMIR2024/visualize_baseline.py new file mode 100644 index 0000000..8e68b7c --- /dev/null +++ b/experiments/TISMIR2024/visualize_baseline.py @@ -0,0 +1,158 @@ +#!/usr/bin/env python + +"""Sanity-check visualization for the LM-SVR baseline (experiments/TISMIR2024). + +Loads the best checkpoint of a trained experiment (identified by its experiment ID, e.g. +"AAT3_LMA_1M_DT", matching a `configs/TISMIR2024/data_splits/*.gin` file), runs it on an +excerpt of that experiment's held-out test take, and plots the signal at each stage of the +signal flow (LM input, TI filter, peak norm, noise synth, TV filter) next to the CM +reference - similar in spirit to Figure 5 of the paper, as a quick visual check that the +reimplementation behaves plausibly (not a quantitative evaluation). + +Usage +----- + uv run experiments/TISMIR2024/visualize_baseline.py AAT3_LMA_1M_DT +""" + +import argparse +import glob +import os +import sys +from pathlib import Path + +import gin +import matplotlib.pyplot as plt +import torch + +# make experiments and scripts directly discoverable, as in `scripts/run.py` +sys.path.insert(0, str(Path(__file__).resolve().parents[2])) + +import experiments.TISMIR2024.lmsvr_baseline # noqa: F401 - registers LMSVRBaselineExperiment +import libdamp # noqa: F401 - registers gin-configurable classes +import scripts.run # noqa: F401 - registers the "libdamp" gin-configurable entry point + +STAGES = ("x_lm", "ti_filtered", "peak_normed", "noisy", "y_hat", "x_cm") +TITLES = { + "x_lm": "$x_{LM}$ (input)", + "ti_filtered": "after TI filter", + "peak_normed": "after peak norm", + "noisy": "after noise synth", + "y_hat": r"$\hat{x}_{CM}$ (output)", + "x_cm": "$x_{CM}$ (reference)", +} + + +def find_run_dir(results_path: str, experiment_id: str) -> str: + """Find the (most recent) results folder for an experiment ID, e.g. 'AAT3_LMA_1M_DT'.""" + matches = sorted(glob.glob(os.path.join(results_path, f"{experiment_id}_*"))) + if not matches: + raise FileNotFoundError(f"No results folder matching '{experiment_id}_*' found in '{results_path}'.") + if len(matches) > 1: + print(f"Multiple runs found for '{experiment_id}', using the most recently modified one: {matches[-1]}") + return max(matches, key=os.path.getmtime) + + +def find_best_checkpoint(run_dir: str) -> str: + """Find the best checkpoint saved for a run (there is only one, since `save_best_n_ckpts=1`).""" + ckpts = sorted(glob.glob(os.path.join(run_dir, "checkpoints", "ckpt_best-*.ckpt"))) + if not ckpts: + raise FileNotFoundError(f"No best checkpoint found in '{run_dir}/checkpoints'.") + return ckpts[-1] + + +def load_experiment_and_val_dataset(run_dir: str, device: str): + """Reconstruct the experiment and its validation dataset from a run's saved operative config. + + This re-instantiates the experiment (with random weights, to be overwritten by a checkpoint) + and the exact train/val/test datasets used for that run, from `run_dir/operative_config.gin` - + i.e. the same mechanism `scripts/run.py` itself uses to go from a gin config to live objects. + """ + with gin.unlock_config(): + gin.parse_config_file(os.path.join(run_dir, "operative_config.gin"), skip_unknown=False) + gin.finalize() + + experiment, _, val_dataset, _ = scripts.run.libdamp_entry_point() + if val_dataset is None: + raise ValueError(f"Run '{run_dir}' was configured without a validation dataset.") + + experiment.eval() + experiment.to(device) + return experiment, val_dataset + + +def pick_loudest_excerpt(signal: torch.Tensor, fs: float, duration: float) -> tuple[int, int]: + """Return the start/end sample indices of the `duration`-second window with the highest RMS energy. + + Used to pick a representative (likely singing, not silent) excerpt from the held-out take. + """ + win = int(fs) + excerpt_len = int(fs * duration) + if signal.shape[-1] <= excerpt_len: + return 0, signal.shape[-1] + + energies = [signal[i : i + win].pow(2).mean() for i in range(0, signal.shape[-1] - win, win)] + center = int(torch.argmax(torch.stack(energies))) * win + win // 2 + + start = min(max(0, center - excerpt_len // 2), signal.shape[-1] - excerpt_len) + return start, start + excerpt_len + + +def spectrogram_db(x: torch.Tensor, n_fft: int = 1024, hop: int = 256) -> torch.Tensor: + """Compute a log-magnitude (dB) spectrogram of a 1D signal.""" + window = torch.hann_window(n_fft).to(x) + X = torch.stft(x, n_fft=n_fft, hop_length=hop, window=window, center=True, return_complex=True) + return 20 * torch.log10(torch.abs(X) + 1e-7) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("experiment_id", type=str, help="experiment ID, e.g. 'AAT3_LMA_1M_DT' (a configs/TISMIR2024/data_splits/*.gin file)") + parser.add_argument("--results-path", type=str, default="results", help="base folder results were saved in (default: 'results')") + parser.add_argument("--duration", type=float, default=6.0, help="length in seconds of the excerpt to visualize (default: 6.0)") + parser.add_argument("--device", type=str, default="cpu", help="torch device to run inference on (default: 'cpu')") + parser.add_argument("--top-db", type=float, default=80.0, help="dynamic range of the spectrogram plots in dB (default: 80.0)") + parser.add_argument("--output", type=str, default=None, help="where to save the figure (default: '/_fig5.png')") + args = parser.parse_args() + + run_dir = find_run_dir(args.results_path, args.experiment_id) + ckpt_path = find_best_checkpoint(run_dir) + print(f"Loading checkpoint: {ckpt_path}") + + experiment, val_dataset = load_experiment_and_val_dataset(run_dir, args.device) + experiment.load_state_dict(torch.load(ckpt_path, map_location=args.device)["state_dict"]) + + if val_dataset.num_takes != 1: + print(f"Warning: expected exactly one held-out take in the validation set, found {val_dataset.num_takes}; using the first one.") + + fs = val_dataset.target_fs + lm_full, cm_full = val_dataset.lm_signals[0], val_dataset.cm_signals[0] + + start, end = pick_loudest_excerpt(cm_full, fs, args.duration) + x_lm = lm_full[start:end].unsqueeze(0).to(args.device) + x_cm = cm_full[start:end].unsqueeze(0).to(args.device) + + with torch.no_grad(): + _, stages = experiment(x_lm, return_intermediates=True) + stages["x_cm"] = x_cm + + specs = {key: spectrogram_db(stages[key].squeeze(0).cpu(), n_fft=1024, hop=256) for key in STAGES} + vmax = max(spec.max().item() for spec in specs.values()) + vmin = vmax - args.top_db + + fig, axes = plt.subplots(1, len(STAGES), figsize=(3.2 * len(STAGES), 3.5), sharey=True) + for ax, key in zip(axes, STAGES, strict=True): + ax.imshow(specs[key], origin="lower", aspect="auto", extent=[0, args.duration, 0, fs / 2], cmap="magma", vmin=vmin, vmax=vmax) + ax.set_title(TITLES[key]) + ax.set_xlabel("Time (s)") + axes[0].set_ylabel("Frequency (Hz)") + + fig.suptitle(f"{args.experiment_id}: baseline signal flow (cf. Fig. 5 of the paper)") + fig.tight_layout() + + output = args.output or os.path.join(run_dir, f"{args.experiment_id}_fig5.png") + fig.savefig(output, dpi=150) + print(f"Saved figure to {output}") + + +if __name__ == "__main__": + main() diff --git a/libdamp/__init__.py b/libdamp/__init__.py index 6335793..5b1fc07 100644 --- a/libdamp/__init__.py +++ b/libdamp/__init__.py @@ -16,6 +16,7 @@ from .datasets import ( CombinedDataset, ExcerptsDataset, + LMSSDDataset, MDBSynthDataset, NSynthDataset, PulseItDataset, @@ -71,6 +72,7 @@ "ZipDataset", "ExcerptsDataset", "SignalF0ExcerptsDataset", + "LMSSDDataset", "MDBSynthDataset", "NSynthDataset", "PulseItDataset", diff --git a/libdamp/datasets/__init__.py b/libdamp/datasets/__init__.py index 549bd3c..af779ba 100644 --- a/libdamp/datasets/__init__.py +++ b/libdamp/datasets/__init__.py @@ -5,6 +5,7 @@ from .combined import CombinedDataset, ZipDataset from .excerpts import ExcerptsDataset, SignalF0ExcerptsDataset +from .lm_ssd import LMSSDDataset from .medleydb import MDBSynthDataset from .nsynth import NSynthDataset from .pulseit import PulseItDataset @@ -15,6 +16,7 @@ "ZipDataset", "ExcerptsDataset", "SignalF0ExcerptsDataset", + "LMSSDDataset", "MDBSynthDataset", "NSynthDataset", "PulseItDataset", diff --git a/libdamp/datasets/lm_ssd.py b/libdamp/datasets/lm_ssd.py new file mode 100644 index 0000000..d464399 --- /dev/null +++ b/libdamp/datasets/lm_ssd.py @@ -0,0 +1,172 @@ +"""Dataset wrapper for the Larynx Microphone Singer-Songwriter Dataset (LM-SSD). + +This module is part of the libdamp package. +""" + +import glob +import os +import re + +import gin +import soundfile as sf +import torch +import torchaudio as taudio + + +@gin.register +class LMSSDDataset(torch.utils.data.Dataset): + """Dataset wrapper for the Larynx Microphone Singer-Songwriter Dataset (LM-SSD). + + LM-SSD (https://doi.org/10.5281/zenodo.20287765) provides paired larynx microphone (LM) recordings + with clean close-up microphone (CM) recordings of the same takes. + Audio files follow the naming convention:: + + SSD[uid]_[song]_[signal]_[crosstalk]_[singer]_[take].wav + + e.g. `SSD001_AB_LM_C0_1M_T1.wav`, where `[signal]` is one of `LM`, `CM`, `GL`, + `GR`, `GP`, `MixA`, `MixB`, `[crosstalk]` is `C0` (no guitar bleed on the CM + signal) or `C1`, `[singer]` identifies the singer (e.g. `1M`), and `[take]` is + `T1`-`T6` (`T1`-`T3` were recorded with microphone LM-A, `T4`-`T6` with LM-B). + + This dataset only uses the `LM`/`CM` pair of each take. It selects takes by applying a + regular expression to the LM file's basename, which makes it possible to choose specific + songs, singers, crosstalk conditions, or takes for a given train/val/test split, e.g. + `selection=r".*_1M_T[1-3]"` for singer 1M, takes recorded with LM-A only. + """ + + def __init__( + self, + path: str, + selection: str = r".*", + target_fs: float = 16000.0, + excerpt_len: int = 64000, + num_excerpts: int = 1000, + min_voice_activity: float = 0.05, + silence_threshold_db: float = -40.0, + random_seed: int | None = None, + ) -> None: + """Dataset wrapper for the Larynx Microphone Singer-Songwriter Dataset (LM-SSD). + + Parameters + ---------- + path : str + Path to the directory containing the LM-SSD audio files (flat directory of `.wav` + files, i.e. the dataset's "audio" folder). + selection : str + Regular expression (matched with `re.search`) against the basename of each LM + file to select which takes are part of this dataset, e.g. to pick specific songs, + singers, crosstalk conditions, or takes. + target_fs : float + Target sampling rate in Hz (loaded audio is resampled if needed). + excerpt_len : int + Length of the randomly selected excerpts in samples, at `target_fs`. + num_excerpts : int + Number of excerpts to pre-select per take (default: 1000). + min_voice_activity : float + Minimum fraction of 20 ms frames within an excerpt that must exceed + `silence_threshold_db` on the LM signal for the excerpt to be accepted during + random pre-selection (default: 0.05). + silence_threshold_db : float + Level, in dB relative to the loudest 20 ms frame of the LM signal, below which + a frame is considered silent (default: -40.0). + random_seed : int or None + Optional random seed for reproducible excerpt selection (default: None). + """ + path = os.path.expanduser(path) + if not os.path.isdir(path): + raise FileNotFoundError(f"Dataset path does not exist: {path}") + + rng = torch.Generator() + if random_seed is not None: + rng.manual_seed(random_seed) + else: + rng.manual_seed(rng.seed()) + + self.excerpt_len = excerpt_len + self.num_excerpts = num_excerpts + self.target_fs = target_fs + + lm_files = sorted(glob.glob(os.path.join(path, "*_LM_*.wav"))) + + # apply selection regex + # (not using glob directly, because it only supports shell-style wildcards instead of complete regex) + pattern = re.compile(selection) + lm_files = [f for f in lm_files if pattern.search(os.path.basename(f))] + + if len(lm_files) == 0: + raise FileNotFoundError(f"No LM-SSD takes matching selection '{selection}' found in {path}") + + self.num_takes = len(lm_files) + + self.lm_signals = [] + self.cm_signals = [] + self.snippet_starts = torch.zeros((self.num_takes, self.num_excerpts), dtype=int) + for i, lm_file in enumerate(lm_files): + cm_file = lm_file.replace("_LM_", "_CM_") + if not os.path.isfile(cm_file): + raise FileNotFoundError(f"No matching CM file found for '{lm_file}' (expected '{cm_file}')") + + x_lm = self._load_resampled(lm_file) + x_cm = self._load_resampled(cm_file) + + L = min(x_lm.shape[-1], x_cm.shape[-1]) + assert self.excerpt_len <= L, f"Take '{os.path.basename(lm_file)}' is shorter than `excerpt_len`." + + self.lm_signals.append(x_lm[:L]) + self.cm_signals.append(x_cm[:L]) + + # avoid pre-selecting excerpts that are completely silent on the LM signal (some + # silence within an excerpt is fine, as long as there is some voice activity) + vad_frame_len = max(1, int(self.target_fs * 0.02)) # 20 ms frames + active = self._voice_activity_mask(x_lm[:L], vad_frame_len, silence_threshold_db) + frames_per_excerpt = max(1, self.excerpt_len // vad_frame_len) + min_active_frames = max(1, int(min_voice_activity * frames_per_excerpt)) + + found = 0 + while found < self.num_excerpts: + start = int(torch.randint(L - self.excerpt_len + 1, (1,), generator=rng)) + start_frame = start // vad_frame_len + if active[start_frame : start_frame + frames_per_excerpt].sum() >= min_active_frames: + self.snippet_starts[i, found] = start + found += 1 + + def _load_resampled(self, file: str) -> torch.Tensor: + """Load a mono audio file and resample it to `self.target_fs` if necessary.""" + x, fs = sf.read(file, always_2d=True) + x = torch.Tensor(x).mean(dim=-1) # ensure mono + if fs != self.target_fs: + x = taudio.transforms.Resample(orig_freq=fs, new_freq=self.target_fs)(x) + return x + + @staticmethod + def _voice_activity_mask(x: torch.Tensor, frame_len: int, threshold_db: float) -> torch.Tensor: + """Return a boolean mask of non-overlapping frames whose RMS exceeds `threshold_db` relative to the loudest frame.""" + num_frames = x.shape[-1] // frame_len + envelope = x[: num_frames * frame_len].view(num_frames, frame_len).pow(2).mean(dim=-1).sqrt() + threshold = envelope.max() * 10 ** (threshold_db / 20) + return envelope > threshold + + def __len__(self): + return self.num_takes * self.num_excerpts + + def __getitem__(self, idx: int) -> tuple[torch.Tensor, torch.Tensor]: + """Get a sample from the dataset. + + Parameters + ---------- + idx : int + Index of the sample to retrieve. + + Returns + ------- + tuple + `(lm_excerpt, cm_excerpt)`, time-aligned excerpts of the larynx microphone and + close-up microphone signals, each of shape `(excerpt_len,)`. + """ + n = idx // self.num_excerpts + m = idx - n * self.num_excerpts + + start = self.snippet_starts[n, m] + end = start + self.excerpt_len + + return self.lm_signals[n][start:end], self.cm_signals[n][start:end] diff --git a/test/datasets/test_lm_ssd.py b/test/datasets/test_lm_ssd.py new file mode 100644 index 0000000..18276e1 --- /dev/null +++ b/test/datasets/test_lm_ssd.py @@ -0,0 +1,94 @@ +"""Unit tests for `libdamp.datasets.lm_ssd`.""" + +import numpy as np +import pytest +import soundfile as sf + +from libdamp.datasets.lm_ssd import LMSSDDataset + + +def _write_take(tmp_path, song, singer, take, crosstalk="C0", fs=16000, duration_s=1.0, uid="001"): + n = int(fs * duration_s) + lm = 0.1 * np.random.randn(n).astype(np.float32) + cm = 0.1 * np.random.randn(n).astype(np.float32) + sf.write(tmp_path / f"SSD{uid}_{song}_LM_{crosstalk}_{singer}_{take}.wav", lm, fs) + sf.write(tmp_path / f"SSD{uid}_{song}_CM_{crosstalk}_{singer}_{take}.wav", cm, fs) + # a non-LM/CM signal that should always be ignored by the dataset + sf.write(tmp_path / f"SSD{uid}_{song}_GL_{crosstalk}_{singer}_{take}.wav", cm, fs) + return lm, cm + + +class TestLMSSDDataset: + def test_missing_path_raises(self, tmp_path): + with pytest.raises(FileNotFoundError): + LMSSDDataset(str(tmp_path / "does_not_exist"), excerpt_len=100, num_excerpts=1) + + def test_selection_regex_filters_takes(self, tmp_path): + _write_take(tmp_path, song="AB", singer="1M", take="T1") + _write_take(tmp_path, song="AB", singer="2M", take="T1") + + ds = LMSSDDataset(str(tmp_path), selection=r"_1M_", excerpt_len=100, num_excerpts=2) + assert ds.num_takes == 1 + assert len(ds) == 2 + + def test_no_match_raises(self, tmp_path): + _write_take(tmp_path, song="AB", singer="1M", take="T1") + with pytest.raises(FileNotFoundError): + LMSSDDataset(str(tmp_path), selection=r"_9X_", excerpt_len=100, num_excerpts=1) + + def test_missing_cm_counterpart_raises(self, tmp_path): + n = 16000 + sf.write(tmp_path / "SSD001_AB_LM_C0_1M_T1.wav", 0.1 * np.random.randn(n).astype(np.float32), 16000) + with pytest.raises(FileNotFoundError): + LMSSDDataset(str(tmp_path), excerpt_len=100, num_excerpts=1) + + def test_getitem_returns_aligned_excerpt_pair(self, tmp_path): + lm, cm = _write_take(tmp_path, song="AB", singer="1M", take="T1", duration_s=1.0) + + ds = LMSSDDataset(str(tmp_path), excerpt_len=100, num_excerpts=3, random_seed=0) + x_lm, x_cm = ds[0] + + assert x_lm.shape == (100,) + assert x_cm.shape == (100,) + + # excerpts must come from a matching position in both signals + start = ds.snippet_starts[0, 0].item() + assert np.allclose(x_lm.numpy(), lm[start : start + 100], atol=1e-4) + assert np.allclose(x_cm.numpy(), cm[start : start + 100], atol=1e-4) + + def test_resamples_to_target_fs(self, tmp_path): + _write_take(tmp_path, song="AB", singer="1M", take="T1", fs=48000, duration_s=1.0) + + ds = LMSSDDataset(str(tmp_path), target_fs=16000.0, excerpt_len=100, num_excerpts=1) + assert ds.lm_signals[0].shape[-1] == pytest.approx(16000, abs=2) + + def test_avoids_completely_silent_excerpts(self, tmp_path): + fs = 16000 + n = fs * 4 # 4 s take + lm = np.zeros(n, dtype=np.float32) + active_start, active_end = 20000, 36000 # the only non-silent region of the LM signal + lm[active_start:active_end] = 0.5 * np.random.randn(active_end - active_start).astype(np.float32) + cm = 0.1 * np.random.randn(n).astype(np.float32) # CM activity is irrelevant to the LM-based VAD check + sf.write(tmp_path / "SSD001_AB_LM_C0_1M_T1.wav", lm, fs) + sf.write(tmp_path / "SSD001_AB_CM_C0_1M_T1.wav", cm, fs) + + excerpt_len = 16000 # 1 s + ds = LMSSDDataset(str(tmp_path), target_fs=fs, excerpt_len=excerpt_len, num_excerpts=50, random_seed=0) + + for start in ds.snippet_starts[0].tolist(): + assert start < active_end and start + excerpt_len > active_start, ( + f"excerpt at {start} does not overlap the only non-silent region [{active_start}, {active_end})" + ) + + def test_mostly_silent_excerpt_with_some_activity_is_accepted(self, tmp_path): + fs = 16000 + n = fs * 4 + lm = np.zeros(n, dtype=np.float32) + lm[: int(fs * 0.3)] = 0.5 * np.random.randn(int(fs * 0.3)).astype(np.float32) # 0.3 s of activity + cm = 0.1 * np.random.randn(n).astype(np.float32) + sf.write(tmp_path / "SSD001_AB_LM_C0_1M_T1.wav", lm, fs) + sf.write(tmp_path / "SSD001_AB_CM_C0_1M_T1.wav", cm, fs) + + # should not hang or raise despite the take being >90% silent + ds = LMSSDDataset(str(tmp_path), target_fs=fs, excerpt_len=16000, num_excerpts=10, random_seed=0) + assert len(ds) == 10 From 8b3abf0aac07cec9dd1ea44bd3956352519cddaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schw=C3=A4r?= Date: Thu, 5 Nov 2026 22:50:18 +0100 Subject: [PATCH 2/7] Fix call to peak_norm --- experiments/TISMIR2024/lmsvr_baseline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/TISMIR2024/lmsvr_baseline.py b/experiments/TISMIR2024/lmsvr_baseline.py index d84e7e8..c62b5d6 100644 --- a/experiments/TISMIR2024/lmsvr_baseline.py +++ b/experiments/TISMIR2024/lmsvr_baseline.py @@ -144,7 +144,7 @@ def forward(self, x, return_intermediates=False): self.ti_filter.update(ti_mag) y_ti = self.ti_filter.process(x) - y_norm = self.peak_norm(y_ti) + y_norm = peak_norm(y_ti) noise = self.noise_synth.generate(noise_mag) y_noisy = y_norm + noise From 064c9e16cb95ee85e7f3cd1d03ba26309578f552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schw=C3=A4r?= Date: Fri, 6 Nov 2026 08:19:52 +0100 Subject: [PATCH 3/7] Make model larger to be more similar to paper approach --- README.md | 8 ++------ configs/TISMIR2024/lmsvr_base.gin | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bd9fd10..f7db81d 100644 --- a/README.md +++ b/README.md @@ -121,12 +121,8 @@ The files in `experiments/TISMIR2024`, `configs/TISMIR2024`, and `libdamp/datase } ``` -Note that this implementation is NOT the same as the one used for the experiments in the paper. In particular, the following differences may lead to slightly different results: -* The Convolutional Network architecture consists of a single stack of 3 convolutional layers - (no residual/skip connections). -* Network outputs are mapped to DSP magnitude parameters with a scaled-sigmoid (`exp_sigmoid`, bias -3, exponent log(10)), following the convention used in the ICASSP2026 experiment. -* Training excerpts are selected at random from each take, and are filtered to skip near-silent excerpts. - +Note that this implementation is NOT the same as the one used for the experiments in the paper. In particular, the NN architecture is simplified, consisting of a single stack of 3 convolutional layers (no residual/skip connections), and a bidirectional LSTM layer. +Also the training procedure and data preprocessing differs. To reproduce results: 1. Download the [LM-SSD](https://zenodo.org/records/20287765) dataset and extract it. diff --git a/configs/TISMIR2024/lmsvr_base.gin b/configs/TISMIR2024/lmsvr_base.gin index be2edde..68a2e77 100644 --- a/configs/TISMIR2024/lmsvr_base.gin +++ b/configs/TISMIR2024/lmsvr_base.gin @@ -31,9 +31,9 @@ LMSVRBaselineExperiment.num_bands_ti = 64 LMSVRBaselineExperiment.num_bands_tv = 64 LMSVRBaselineExperiment.num_bands_noise = 10 -LMSVRBaselineExperiment.model_size_control = 128 +LMSVRBaselineExperiment.model_size_control = 512 -LMSVRBaselineExperiment.learning_rate = 1e-3 +LMSVRBaselineExperiment.learning_rate = 1e-4 LMSVRBaselineExperiment.loss_fn = @MSSLoss() MSSLoss.w_mag = 1.0 From bc85643a387e91a03b85a95f2d1a0e07db63566a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schw=C3=A4r?= Date: Fri, 6 Nov 2026 08:26:12 +0100 Subject: [PATCH 4/7] Make bias initialization of filter heads more similar to paper --- experiments/TISMIR2024/lmsvr_baseline.py | 25 ++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/experiments/TISMIR2024/lmsvr_baseline.py b/experiments/TISMIR2024/lmsvr_baseline.py index c62b5d6..c078552 100644 --- a/experiments/TISMIR2024/lmsvr_baseline.py +++ b/experiments/TISMIR2024/lmsvr_baseline.py @@ -21,8 +21,7 @@ def peak_norm(x, eps=1e-7): - """Normalize each signal in the batch to unit peak amplitude. - """ + """Normalize each signal in the batch to unit peak amplitude.""" peak = x.abs().amax(dim=-1, keepdim=True) return x / (peak + eps) @@ -111,6 +110,12 @@ def __init__( self.noise_head = torch.nn.Linear(model_size_control, num_bands_noise) self.tv_head = torch.nn.Linear(model_size_control, num_bands_tv) + # bias init following the original paper: + # TI ramps 0.5->2.0 (treble boost), noise starts quiet, TV starts near-identity + self.ti_head.bias.data.copy_(torch.linspace(0.5, 2.0, num_bands_ti)) + self.noise_head.bias.data.fill_(-1.0) + self.tv_head.bias.data.fill_(1.0) + self.ti_filter = libdamp.processors.TVMagnitudesFilter( frame_len, filt_len, fs, center_freqs=torch.linspace(0, fs / 2, num_bands_ti), filter_phase="linear" ) @@ -118,26 +123,22 @@ def __init__( frame_len, filt_len, fs, center_freqs=torch.linspace(0, fs / 2, num_bands_tv), filter_phase="linear" ) - self.noise_synth = libdamp.generators.SimpleFilteredNoise( - frame_len, filt_len, fs, torch.linspace(0, fs / 2, num_bands_noise) - ) + self.noise_synth = libdamp.generators.SimpleFilteredNoise(frame_len, filt_len, fs, torch.linspace(0, fs / 2, num_bands_noise)) def estimate_params(self, x): - """Estimate TI filter, TV filter, and noise synthesizer magnitudes from the LM input. - """ + """Estimate TI filter, TV filter, and noise synthesizer magnitudes from the LM input.""" mel = torch.log(1 + self.mel_transform(x.unsqueeze(-2))) feat = self.control_cnn(mel) feat = self.control_rnn(feat) - ti_mag = libdamp.exp_sigmoid(self.ti_head(feat.mean(dim=1, keepdim=True)) - 3, exp=math.log(10.0)) - noise_mag = libdamp.exp_sigmoid(self.noise_head(feat) - 3, exp=math.log(10.0)) - tv_mag = libdamp.exp_sigmoid(self.tv_head(feat) - 3, exp=math.log(10.0)) + ti_mag = libdamp.exp_sigmoid(self.ti_head(feat.mean(dim=1, keepdim=True)), exp=math.log(10.0)) + noise_mag = libdamp.exp_sigmoid(self.noise_head(feat), exp=math.log(10.0)) + tv_mag = libdamp.exp_sigmoid(self.tv_head(feat), exp=math.log(10.0)) return ti_mag, tv_mag, noise_mag def forward(self, x, return_intermediates=False): - """Forward pass implementation. - """ + """Forward pass implementation.""" ti_mag, tv_mag, noise_mag = self.estimate_params(x) self.ti_filter.clear() From 4884c889215e4678dd8e76d4bbdd6bdd2b50600e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schw=C3=A4r?= Date: Fri, 6 Nov 2026 08:41:44 +0100 Subject: [PATCH 5/7] Add experiment inspection notebook --- configs/TISMIR2024/lmsvr_base.gin | 4 +- experiments/TISMIR2024/visualize_baseline.py | 158 --------------- notebooks/TISMIR2024/load_model.ipynb | 192 +++++++++++++++++++ 3 files changed, 194 insertions(+), 160 deletions(-) delete mode 100644 experiments/TISMIR2024/visualize_baseline.py create mode 100644 notebooks/TISMIR2024/load_model.ipynb diff --git a/configs/TISMIR2024/lmsvr_base.gin b/configs/TISMIR2024/lmsvr_base.gin index 68a2e77..6b44112 100644 --- a/configs/TISMIR2024/lmsvr_base.gin +++ b/configs/TISMIR2024/lmsvr_base.gin @@ -4,7 +4,7 @@ include 'configs/base.gin' Experiment.name = "tismir2024_lmsvr_{date}" Experiment.early_stopping = False Experiment.save_best_n_ckpts = 1 -Experiment.max_epochs = 40 +Experiment.max_epochs = 100 Experiment.batch_size = 32 Experiment.limit_val_batches = 1.0 Experiment.shuffle_data = True @@ -41,7 +41,7 @@ MSSLoss.w_log = 1.0 MSSLoss.fft_sizes = (2048, 1024, 512, 256, 128, 64) MSSLoss.win = "hann" -dataset_path = "~/Desktop/datasets/lm-ssd/LM-SSD/audio" +dataset_path = "~/datasets/lm-ssd/LM-SSD/audio" # The exact data splits are defined in the separate config files in the subfolder "data_splits" libdamp.train_dataset = @train/LMSSDDataset() diff --git a/experiments/TISMIR2024/visualize_baseline.py b/experiments/TISMIR2024/visualize_baseline.py deleted file mode 100644 index 8e68b7c..0000000 --- a/experiments/TISMIR2024/visualize_baseline.py +++ /dev/null @@ -1,158 +0,0 @@ -#!/usr/bin/env python - -"""Sanity-check visualization for the LM-SVR baseline (experiments/TISMIR2024). - -Loads the best checkpoint of a trained experiment (identified by its experiment ID, e.g. -"AAT3_LMA_1M_DT", matching a `configs/TISMIR2024/data_splits/*.gin` file), runs it on an -excerpt of that experiment's held-out test take, and plots the signal at each stage of the -signal flow (LM input, TI filter, peak norm, noise synth, TV filter) next to the CM -reference - similar in spirit to Figure 5 of the paper, as a quick visual check that the -reimplementation behaves plausibly (not a quantitative evaluation). - -Usage ------ - uv run experiments/TISMIR2024/visualize_baseline.py AAT3_LMA_1M_DT -""" - -import argparse -import glob -import os -import sys -from pathlib import Path - -import gin -import matplotlib.pyplot as plt -import torch - -# make experiments and scripts directly discoverable, as in `scripts/run.py` -sys.path.insert(0, str(Path(__file__).resolve().parents[2])) - -import experiments.TISMIR2024.lmsvr_baseline # noqa: F401 - registers LMSVRBaselineExperiment -import libdamp # noqa: F401 - registers gin-configurable classes -import scripts.run # noqa: F401 - registers the "libdamp" gin-configurable entry point - -STAGES = ("x_lm", "ti_filtered", "peak_normed", "noisy", "y_hat", "x_cm") -TITLES = { - "x_lm": "$x_{LM}$ (input)", - "ti_filtered": "after TI filter", - "peak_normed": "after peak norm", - "noisy": "after noise synth", - "y_hat": r"$\hat{x}_{CM}$ (output)", - "x_cm": "$x_{CM}$ (reference)", -} - - -def find_run_dir(results_path: str, experiment_id: str) -> str: - """Find the (most recent) results folder for an experiment ID, e.g. 'AAT3_LMA_1M_DT'.""" - matches = sorted(glob.glob(os.path.join(results_path, f"{experiment_id}_*"))) - if not matches: - raise FileNotFoundError(f"No results folder matching '{experiment_id}_*' found in '{results_path}'.") - if len(matches) > 1: - print(f"Multiple runs found for '{experiment_id}', using the most recently modified one: {matches[-1]}") - return max(matches, key=os.path.getmtime) - - -def find_best_checkpoint(run_dir: str) -> str: - """Find the best checkpoint saved for a run (there is only one, since `save_best_n_ckpts=1`).""" - ckpts = sorted(glob.glob(os.path.join(run_dir, "checkpoints", "ckpt_best-*.ckpt"))) - if not ckpts: - raise FileNotFoundError(f"No best checkpoint found in '{run_dir}/checkpoints'.") - return ckpts[-1] - - -def load_experiment_and_val_dataset(run_dir: str, device: str): - """Reconstruct the experiment and its validation dataset from a run's saved operative config. - - This re-instantiates the experiment (with random weights, to be overwritten by a checkpoint) - and the exact train/val/test datasets used for that run, from `run_dir/operative_config.gin` - - i.e. the same mechanism `scripts/run.py` itself uses to go from a gin config to live objects. - """ - with gin.unlock_config(): - gin.parse_config_file(os.path.join(run_dir, "operative_config.gin"), skip_unknown=False) - gin.finalize() - - experiment, _, val_dataset, _ = scripts.run.libdamp_entry_point() - if val_dataset is None: - raise ValueError(f"Run '{run_dir}' was configured without a validation dataset.") - - experiment.eval() - experiment.to(device) - return experiment, val_dataset - - -def pick_loudest_excerpt(signal: torch.Tensor, fs: float, duration: float) -> tuple[int, int]: - """Return the start/end sample indices of the `duration`-second window with the highest RMS energy. - - Used to pick a representative (likely singing, not silent) excerpt from the held-out take. - """ - win = int(fs) - excerpt_len = int(fs * duration) - if signal.shape[-1] <= excerpt_len: - return 0, signal.shape[-1] - - energies = [signal[i : i + win].pow(2).mean() for i in range(0, signal.shape[-1] - win, win)] - center = int(torch.argmax(torch.stack(energies))) * win + win // 2 - - start = min(max(0, center - excerpt_len // 2), signal.shape[-1] - excerpt_len) - return start, start + excerpt_len - - -def spectrogram_db(x: torch.Tensor, n_fft: int = 1024, hop: int = 256) -> torch.Tensor: - """Compute a log-magnitude (dB) spectrogram of a 1D signal.""" - window = torch.hann_window(n_fft).to(x) - X = torch.stft(x, n_fft=n_fft, hop_length=hop, window=window, center=True, return_complex=True) - return 20 * torch.log10(torch.abs(X) + 1e-7) - - -def main(): - parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument("experiment_id", type=str, help="experiment ID, e.g. 'AAT3_LMA_1M_DT' (a configs/TISMIR2024/data_splits/*.gin file)") - parser.add_argument("--results-path", type=str, default="results", help="base folder results were saved in (default: 'results')") - parser.add_argument("--duration", type=float, default=6.0, help="length in seconds of the excerpt to visualize (default: 6.0)") - parser.add_argument("--device", type=str, default="cpu", help="torch device to run inference on (default: 'cpu')") - parser.add_argument("--top-db", type=float, default=80.0, help="dynamic range of the spectrogram plots in dB (default: 80.0)") - parser.add_argument("--output", type=str, default=None, help="where to save the figure (default: '/_fig5.png')") - args = parser.parse_args() - - run_dir = find_run_dir(args.results_path, args.experiment_id) - ckpt_path = find_best_checkpoint(run_dir) - print(f"Loading checkpoint: {ckpt_path}") - - experiment, val_dataset = load_experiment_and_val_dataset(run_dir, args.device) - experiment.load_state_dict(torch.load(ckpt_path, map_location=args.device)["state_dict"]) - - if val_dataset.num_takes != 1: - print(f"Warning: expected exactly one held-out take in the validation set, found {val_dataset.num_takes}; using the first one.") - - fs = val_dataset.target_fs - lm_full, cm_full = val_dataset.lm_signals[0], val_dataset.cm_signals[0] - - start, end = pick_loudest_excerpt(cm_full, fs, args.duration) - x_lm = lm_full[start:end].unsqueeze(0).to(args.device) - x_cm = cm_full[start:end].unsqueeze(0).to(args.device) - - with torch.no_grad(): - _, stages = experiment(x_lm, return_intermediates=True) - stages["x_cm"] = x_cm - - specs = {key: spectrogram_db(stages[key].squeeze(0).cpu(), n_fft=1024, hop=256) for key in STAGES} - vmax = max(spec.max().item() for spec in specs.values()) - vmin = vmax - args.top_db - - fig, axes = plt.subplots(1, len(STAGES), figsize=(3.2 * len(STAGES), 3.5), sharey=True) - for ax, key in zip(axes, STAGES, strict=True): - ax.imshow(specs[key], origin="lower", aspect="auto", extent=[0, args.duration, 0, fs / 2], cmap="magma", vmin=vmin, vmax=vmax) - ax.set_title(TITLES[key]) - ax.set_xlabel("Time (s)") - axes[0].set_ylabel("Frequency (Hz)") - - fig.suptitle(f"{args.experiment_id}: baseline signal flow (cf. Fig. 5 of the paper)") - fig.tight_layout() - - output = args.output or os.path.join(run_dir, f"{args.experiment_id}_fig5.png") - fig.savefig(output, dpi=150) - print(f"Saved figure to {output}") - - -if __name__ == "__main__": - main() diff --git a/notebooks/TISMIR2024/load_model.ipynb b/notebooks/TISMIR2024/load_model.ipynb new file mode 100644 index 0000000..c958e06 --- /dev/null +++ b/notebooks/TISMIR2024/load_model.ipynb @@ -0,0 +1,192 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "0", + "metadata": {}, + "outputs": [], + "source": [ + "import glob\n", + "import os\n", + "import sys\n", + "\n", + "import gin\n", + "import IPython.display as ipd\n", + "import librosa\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import pandas as pd\n", + "import torch\n", + "\n", + "gin.enter_interactive_mode()\n", + "\n", + "\n", + "@gin.configurable(\"libdamp\")\n", + "def libdamp_entry_point(experiment=gin.REQUIRED, train_dataset=gin.REQUIRED, val_dataset=None, test_dataset=None):\n", + " \"\"\"Entrance function for specifying an experiment and dataset for training in the gin config\n", + "\n", + " Example usage in the gin config:\n", + " ```\n", + " torchdsp.experiment = @MyModel\n", + " torchdsp.train_dataset = @MyTrainDataset\n", + " torchdsp.val_dataset = @MyValDataset\n", + " torchdsp.test_dataset = @MyTestDataset\n", + " ```\n", + "\n", + " Validation and test datasets are optional.\n", + " Attention: The function name conflicts with the module name, but this is only relevant in this file.\n", + " \"\"\"\n", + " return experiment, train_dataset, val_dataset, test_dataset" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1", + "metadata": {}, + "outputs": [], + "source": [ + "fs = 16000.0\n", + "exp_id = \"AAT3_LMA_1M_OF_20261106_082646\"\n", + "\n", + "sys.path.append(\"..\")\n", + "\n", + "# load operative gin config\n", + "gin.clear_config()\n", + "with gin.unlock_config():\n", + " gin.parse_config_file(os.path.join(\"../results\", exp_id, \"operative_config.gin\"), skip_unknown=True)\n", + "\n", + "# create model and datasets\n", + "model, train_dataset, val_dataset, test_dataset = libdamp_entry_point()\n", + "\n", + "best_ckpt = glob.glob(os.path.join(\"../results\", exp_id, \"checkpoints/*best*.ckpt\"))[0]\n", + "last_ckpt = os.path.join(\"../results\", exp_id, \"checkpoints/last.ckpt\")\n", + "\n", + "# load the best checkpoint and configure the weights of the model\n", + "ckpt = torch.load(best_ckpt, map_location=\"cpu\")\n", + "sd = ckpt[\"state_dict\"]\n", + "\n", + "model.load_state_dict(sd)\n", + "# model = model.cuda()\n", + "_ = model.eval()\n", + "\n", + "assert model.fs == fs, \"Sampling rate mismatch\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2", + "metadata": {}, + "outputs": [], + "source": [ + "# plot training and validation loss\n", + "steps_per_epoch = 188 # for calculating the epoch average\n", + "\n", + "log = pd.read_csv(os.path.join(\"../results\", exp_id, \"csv_log/metrics.csv\"))\n", + "train_loss = log[log[\"train_loss_step\"].notnull()]\n", + "train_loss_epoch = log[log[\"train_loss_epoch\"].notnull()]\n", + "val_loss = log[log[\"val_loss\"].notnull()]\n", + "\n", + "idx = train_loss_epoch[\"train_loss_epoch\"].argmin()\n", + "print(f\"Best train loss: {train_loss_epoch['train_loss_epoch'].iloc[idx]:.4f} (epoch {train_loss_epoch['step'].iloc[idx] / steps_per_epoch:.0f})\")\n", + "print(f\"Best val loss: {val_loss['val_loss'].min():.4f}, last val los: {val_loss['val_loss'].iloc[-1]:.4f}\")\n", + "\n", + "plt.plot(train_loss[\"step\"], train_loss[\"train_loss_step\"], label=\"train\")\n", + "plt.plot(train_loss_epoch[\"step\"] - 0.5 * steps_per_epoch, train_loss_epoch[\"train_loss_epoch\"], label=\"train (epoch average)\")\n", + "plt.plot(val_loss[\"step\"], val_loss[\"val_loss\"], label=\"validation\")\n", + "plt.legend()\n", + "plt.yscale(\"log\")\n", + "plt.xlabel(\"Step\")\n", + "plt.ylabel(\"Loss\")\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3", + "metadata": {}, + "outputs": [], + "source": [ + "# load audio\n", + "x, _ = librosa.load(\"/home/sws/datasets/lm-ssd/LM-SSD/audio/SSD003_AA_LM_C0_1M_T3.wav\", sr=fs)\n", + "y_ref, _ = librosa.load(\"/home/sws/datasets/lm-ssd/LM-SSD/audio/SSD003_AA_CM_C0_1M_T3.wav\", sr=fs)\n", + "\n", + "# choose a good excerpt and convert to Tensors in the right shape\n", + "start = 46.5\n", + "duration = 20\n", + "x = torch.Tensor(x)[None, int(start * fs):int((start + duration) * fs)]\n", + "y_ref = y_ref[int(start * fs):int((start + duration) * fs)]\n", + "\n", + "# run model\n", + "y, signals = model(x, return_intermediates=True)\n", + "y = y.detach()\n", + "\n", + "# visualize\n", + "H = 1024\n", + "N = 4096\n", + "gamma = 10\n", + "\n", + "X = np.abs(librosa.stft(x[0].numpy(), n_fft=N, hop_length=H))\n", + "Y = np.abs(librosa.stft(y[0].numpy(), n_fft=N, hop_length=H))\n", + "Y_ref = np.abs(librosa.stft(y_ref, n_fft=N, hop_length=H))\n", + "\n", + "t_ = np.arange(X.shape[1]) * H / fs + start\n", + "f_ = np.arange(X.shape[0]) * fs / N\n", + "\n", + "_, axs = plt.subplots(3, 1, figsize=(8, 6), dpi=150, sharex=True)\n", + "\n", + "axs[0].set_title(\"CM\", size=7)\n", + "axs[0].pcolormesh(t_, f_ / 1000, np.log(1 + 5 * Y_ref), cmap=\"gray_r\")\n", + "axs[0].set_ylim(0.05, 5.5)\n", + "axs[0].set_ylabel(\"Freq. (kHz)\")\n", + "\n", + "axs[1].set_title(\"LM\", size=7)\n", + "axs[1].pcolormesh(t_, f_ / 1000, np.log(1 + 5 * X), cmap=\"gray_r\")\n", + "axs[1].set_ylim(0.05, 5.5)\n", + "axs[1].set_ylabel(\"Freq. (kHz)\")\n", + "\n", + "axs[2].set_title(\"Reconstructed from LM\", size=7)\n", + "axs[2].pcolormesh(t_, f_ / 1000, np.log(1 + 5 * Y), cmap=\"gray_r\")\n", + "axs[2].set_ylim(0.05, 5.5)\n", + "axs[2].set_ylabel(\"Freq. (kHz)\")\n", + "\n", + "axs[-1].set_xlabel(\"Time (s)\")\n", + "\n", + "plt.tight_layout()\n", + "\n", + "plt.show()\n", + "\n", + "print(\"CM:\")\n", + "ipd.display(ipd.Audio(np.repeat(y_ref[None,:], 2, axis=0), rate=fs))\n", + "print(\"LM:\")\n", + "ipd.display(ipd.Audio(np.repeat(x.numpy(), 2, axis=0), rate=fs))\n", + "print(\"Reconstructed from LM:\")\n", + "ipd.display(ipd.Audio(np.repeat(y.numpy(), 2, axis=0), rate=fs))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 1b5f7f57e087c13cc768b55ce26f6f54ea56c679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schw=C3=A4r?= Date: Fri, 6 Nov 2026 08:43:09 +0100 Subject: [PATCH 6/7] Update readme with notebook info --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index f7db81d..ae01cde 100644 --- a/README.md +++ b/README.md @@ -132,8 +132,7 @@ To reproduce results: * **OF:** overfitting, the held-out take is also included in training * **DT:** different take, the one evaluation take is excluded from an otherwise identical training set * **DS:** different song, all takes of the evaluation take's song are excluded. -4. Trained models are stored in the `results` folder using a descriptive name. -5. For a quick sanity check of a trained model, run `uv run experiments/TISMIR2024/visualize_baseline.py ` (e.g. `AAT3_LMA_1M_DT`, needs the `notebooks` extra for `matplotlib`). It loads that experiment's best checkpoint, runs it on an excerpt of the held-out test take, and saves a plot of the signal at each stage of the signal flow next to the CM reference (similar to Fig. 5 in the paper). +4. Trained models are stored in the `results` folder. You can load them and play around with them using the notebook `notebooks/TISMIR2024/load_model.ipynb`. ### Vocal Revolutions From 504daf711500375d3e768d38e0e32eee6cca75ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schw=C3=A4r?= Date: Fri, 6 Nov 2026 08:46:24 +0100 Subject: [PATCH 7/7] Run formatting on notebook --- notebooks/TISMIR2024/load_model.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/notebooks/TISMIR2024/load_model.ipynb b/notebooks/TISMIR2024/load_model.ipynb index c958e06..dcb0272 100644 --- a/notebooks/TISMIR2024/load_model.ipynb +++ b/notebooks/TISMIR2024/load_model.ipynb @@ -117,8 +117,8 @@ "# choose a good excerpt and convert to Tensors in the right shape\n", "start = 46.5\n", "duration = 20\n", - "x = torch.Tensor(x)[None, int(start * fs):int((start + duration) * fs)]\n", - "y_ref = y_ref[int(start * fs):int((start + duration) * fs)]\n", + "x = torch.Tensor(x)[None, int(start * fs) : int((start + duration) * fs)]\n", + "y_ref = y_ref[int(start * fs) : int((start + duration) * fs)]\n", "\n", "# run model\n", "y, signals = model(x, return_intermediates=True)\n", @@ -160,7 +160,7 @@ "plt.show()\n", "\n", "print(\"CM:\")\n", - "ipd.display(ipd.Audio(np.repeat(y_ref[None,:], 2, axis=0), rate=fs))\n", + "ipd.display(ipd.Audio(np.repeat(y_ref[None, :], 2, axis=0), rate=fs))\n", "print(\"LM:\")\n", "ipd.display(ipd.Audio(np.repeat(x.numpy(), 2, axis=0), rate=fs))\n", "print(\"Reconstructed from LM:\")\n",