-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #399 from claritychallenge/371-CAD2
Adding Cadenza 2
- Loading branch information
Showing
47 changed files
with
5,362 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from clarity.enhancer.multiband_compressor.compressor_qmul import Compressor | ||
from clarity.enhancer.multiband_compressor.crossover import Crossover | ||
from clarity.enhancer.multiband_compressor.multiband_compressor import ( | ||
MultibandCompressor, | ||
) | ||
|
||
__all__ = ["MultibandCompressor", "Compressor", "Crossover"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# The Second Cadenza Challenge | ||
|
||
Cadenza challenge code for the Second Cadenza Challenge (CAD2). | ||
For more information please visit the [challenge website](https://cadenzachallenge.org/docs/cadenza2/intro). | ||
|
||
In the directories `task 1` and `task 2`, you will find the code for the baseline | ||
for each system and the instruction on how to obtain the data. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# CAD2-TASK1 singing/accompaniment separation model | ||
|
||
This recipe contains the necessary content to replicate the separation models used in CAD2-Task1. | ||
|
||
- The system is based on Asteroid Source Separation system. | ||
- ConvTasNet implementation is based on stereo adaptation by Alexandre Defossez <https://github.com/facebookresearch/demucs/blob/v1/demucs/tasnet.py> | ||
- Evaluation logic is based on <https://github.com/asteroid-team/asteroid/blob/master/egs/musdb18/X-UMX/eval.py> | ||
- Dataloader is based on <https://github.com/asteroid-team/asteroid/blob/master/asteroid/data/musdb18_dataset.py> | ||
|
||
You can replicate the Causal and Non-Causal model by running: | ||
|
||
- **To replicate the Non-Causal model** | ||
|
||
```bash | ||
python train.py \ | ||
--exp_dir /path/to/save/exps \ | ||
--batch_size 4 \ | ||
--aggregate 2 \ | ||
--lr 0.0005 \ | ||
--root /path/to/MUSDB18 \ | ||
--sample_rate 44100 \ | ||
--segment 5.0 \ | ||
--samples_per_track 64 | ||
``` | ||
|
||
- **To replicate the Causal model** | ||
|
||
```bash | ||
python train.py \ | ||
--exp_dir /path/to/save/exps \ | ||
--batch_size 4 \ | ||
--aggregate 1 \ | ||
--lr 0.0005 \ | ||
--root /path/to/MUSDB18 \ | ||
--sample_rate 44100 \ | ||
--segment 4.0 \ | ||
--samples_per_track 64 \ | ||
--causal True \ | ||
--n_src 2 \ | ||
--norm_type cLN | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import argparse | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
import musdb | ||
import museval | ||
import soundfile as sf | ||
import torch | ||
import yaml | ||
from local import ConvTasNetStereo | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--out_dir", | ||
type=str, | ||
required=True, | ||
help="Directory in exp_dir where the eval results will be stored", | ||
) | ||
parser.add_argument( | ||
"--use_gpu", type=int, default=0, help="Whether to use the GPU for model execution" | ||
) | ||
parser.add_argument("--exp_dir", default="exp/tmp", help="Experiment root") | ||
parser.add_argument( | ||
"--n_save_ex", | ||
type=int, | ||
default=10, | ||
help="Number of audio examples to save, -1 means all", | ||
) | ||
|
||
compute_metrics = ["si_sdr", "sdr", "sir", "sar"] | ||
|
||
|
||
def main(conf): | ||
model_path = os.path.join(conf["exp_dir"], "best_model.pth") | ||
|
||
model = ConvTasNetStereo( | ||
**conf["train_conf"]["convtasnet"], | ||
samplerate=conf["train_conf"]["data"]["sample_rate"], | ||
) | ||
|
||
saved = torch.load(model_path, map_location="cpu") | ||
model.load_state_dict(saved["state_dict"]) | ||
|
||
# Handle device placement | ||
if conf["use_gpu"]: | ||
model.cuda() | ||
|
||
model_device = next(model.parameters()).device | ||
|
||
# Evaluation is mode using 'remix' mixture | ||
test_set = musdb.DB( | ||
root=conf["train_conf"]["data"]["root"], subsets="test", is_wav=True | ||
) | ||
results = museval.EvalStore() | ||
|
||
# Randomly choose the indexes of sentences to save. | ||
eval_save_dir = os.path.join(conf["exp_dir"], conf["out_dir"]) | ||
Path(eval_save_dir).mkdir(exist_ok=True, parents=True) | ||
|
||
txtout = os.path.join(eval_save_dir, "results.txt") | ||
fp = open(txtout, "w") | ||
|
||
torch.no_grad().__enter__() | ||
for track in test_set: | ||
input_file = os.path.join( | ||
conf["train_conf"]["data"]["root"], "test", track.name, "mixture.wav" | ||
) | ||
# Forward the network on the mixture. | ||
mix, rate = sf.read(input_file, always_2d=True, start=0, stop=None) | ||
|
||
# Separate | ||
mix = torch.tensor(mix.T, dtype=torch.float).to(model_device) | ||
|
||
est_sources = model.forward(mix.unsqueeze(0)) | ||
est_sources = est_sources.squeeze(0).cpu().data.numpy() | ||
|
||
estimates = {} | ||
estimates["vocals"] = est_sources[0].T | ||
estimates["accompaniment"] = est_sources[1].T | ||
|
||
output_path = Path(os.path.join(eval_save_dir, track.name)) | ||
output_path.mkdir(exist_ok=True, parents=True) | ||
|
||
print(f"Processing... {track.name}", file=sys.stderr) | ||
print(track.name, file=fp) | ||
|
||
for target, estimate in estimates.items(): | ||
sf.write( | ||
str(output_path / Path(target).with_suffix(".wav")), | ||
estimate, | ||
conf["train_conf"]["data"]["sample_rate"], | ||
) | ||
track_scores = museval.eval_mus_track(track, estimates) | ||
results.add_track(track_scores.df) | ||
print(track_scores, file=sys.stderr) | ||
print(track_scores, file=fp) | ||
print(results, file=sys.stderr) | ||
print(results, file=fp) | ||
results.save(os.path.join(eval_save_dir, "results.pandas")) | ||
results.frames_agg = "mean" | ||
print(results, file=sys.stderr) | ||
print(results, file=fp) | ||
fp.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parser.parse_args() | ||
arg_dic = dict(vars(args)) | ||
# Load training config | ||
conf_path = os.path.join(args.exp_dir, "conf.yml") | ||
with open(conf_path) as f: | ||
train_conf = yaml.safe_load(f) | ||
arg_dic["sample_rate"] = train_conf["data"]["sample_rate"] | ||
arg_dic["train_conf"] = train_conf | ||
|
||
main(arg_dic) | ||
|
||
print("Done!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from .musdb18_dataset import Compose, MUSDB18Dataset, augment_channelswap, augment_gain | ||
from .tasnet import ConvTasNetStereo, overlap_and_add | ||
|
||
__all__ = [ | ||
"MUSDB18Dataset", | ||
"Compose", | ||
"augment_gain", | ||
"augment_channelswap", | ||
"ConvTasNetStereo", | ||
"overlap_and_add", | ||
] |
Oops, something went wrong.