Last active
December 22, 2020 10:42
-
-
Save jonashaag/de1759248db14e57120346ef6b9589f2 to your computer and use it in GitHub Desktop.
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
hop | dev | dtype | win | impl | error (dB) | |
---|---|---|---|---|---|---|
32 | cuda | torch.float32 | ones | torch.stft | 92 | |
32 | cuda | torch.float32 | ones | stft_fb | 30 | |
32 | cuda | torch.float32 | ones | torch_stft_fb | 92 | |
32 | cuda | torch.float32 | ones | librosa | 92 | |
32 | cuda | torch.float32 | librosa | torch.stft | 92 | |
32 | cuda | torch.float32 | librosa | stft_fb | 29 | |
32 | cuda | torch.float32 | librosa | torch_stft_fb | 92 | |
32 | cuda | torch.float32 | librosa | librosa | 92 | |
32 | cuda | torch.float32 | asteroid | torch.stft | 92 | |
32 | cuda | torch.float32 | asteroid | stft_fb | 30 | |
32 | cuda | torch.float32 | asteroid | torch_stft_fb | 92 | |
32 | cuda | torch.float32 | asteroid | librosa | 92 | |
64 | cuda | torch.float32 | ones | torch.stft | 92 | |
64 | cuda | torch.float32 | ones | stft_fb | 31 | |
64 | cuda | torch.float32 | ones | torch_stft_fb | 92 | |
64 | cuda | torch.float32 | ones | librosa | 92 | |
64 | cuda | torch.float32 | librosa | torch.stft | 92 | |
64 | cuda | torch.float32 | librosa | stft_fb | 30 | |
64 | cuda | torch.float32 | librosa | torch_stft_fb | 92 | |
64 | cuda | torch.float32 | librosa | librosa | 92 | |
64 | cuda | torch.float32 | asteroid | torch.stft | 92 | |
64 | cuda | torch.float32 | asteroid | stft_fb | 30 | |
64 | cuda | torch.float32 | asteroid | torch_stft_fb | 92 | |
64 | cuda | torch.float32 | asteroid | librosa | 92 | |
128 | cuda | torch.float32 | ones | torch.stft | 92 | |
128 | cuda | torch.float32 | ones | stft_fb | 32 | |
128 | cuda | torch.float32 | ones | torch_stft_fb | 92 | |
128 | cuda | torch.float32 | ones | librosa | 92 | |
128 | cuda | torch.float32 | librosa | torch.stft | 92 | |
128 | cuda | torch.float32 | librosa | stft_fb | 30 | |
128 | cuda | torch.float32 | librosa | torch_stft_fb | 92 | |
128 | cuda | torch.float32 | librosa | librosa | 92 | |
128 | cuda | torch.float32 | asteroid | torch.stft | 92 | |
128 | cuda | torch.float32 | asteroid | stft_fb | 31 | |
128 | cuda | torch.float32 | asteroid | torch_stft_fb | 92 | |
128 | cuda | torch.float32 | asteroid | librosa | 92 | |
256 | cuda | torch.float32 | ones | torch.stft | 92 | |
256 | cuda | torch.float32 | ones | stft_fb | 34 | |
256 | cuda | torch.float32 | ones | torch_stft_fb | 92 | |
256 | cuda | torch.float32 | ones | librosa | 92 | |
256 | cuda | torch.float32 | librosa | torch.stft | 92 | |
256 | cuda | torch.float32 | librosa | stft_fb | 12 | |
256 | cuda | torch.float32 | librosa | torch_stft_fb | 92 | |
256 | cuda | torch.float32 | librosa | librosa | 92 | |
256 | cuda | torch.float32 | asteroid | torch.stft | 92 | |
256 | cuda | torch.float32 | asteroid | stft_fb | 32 | |
256 | cuda | torch.float32 | asteroid | torch_stft_fb | 92 | |
256 | cuda | torch.float32 | asteroid | librosa | 92 | |
384 | cuda | torch.float32 | ones | torch.stft | 92 | |
384 | cuda | torch.float32 | ones | stft_fb | 9 | |
384 | cuda | torch.float32 | ones | torch_stft_fb | 92 | |
384 | cuda | torch.float32 | ones | librosa | 92 | |
384 | cuda | torch.float32 | librosa | torch.stft | 92 | |
384 | cuda | torch.float32 | librosa | stft_fb | 3 | |
384 | cuda | torch.float32 | librosa | torch_stft_fb | 92 | |
384 | cuda | torch.float32 | librosa | librosa | 92 | |
384 | cuda | torch.float32 | asteroid | torch.stft | 92 | |
384 | cuda | torch.float32 | asteroid | stft_fb | 8 | |
384 | cuda | torch.float32 | asteroid | torch_stft_fb | 92 | |
384 | cuda | torch.float32 | asteroid | librosa | 92 | |
480 | cuda | torch.float32 | ones | torch.stft | 92 | |
480 | cuda | torch.float32 | ones | stft_fb | 13 | |
480 | cuda | torch.float32 | ones | torch_stft_fb | 92 | |
480 | cuda | torch.float32 | ones | librosa | 92 | |
480 | cuda | torch.float32 | librosa | torch.stft | 91 | |
480 | cuda | torch.float32 | librosa | stft_fb | 0 | |
480 | cuda | torch.float32 | librosa | torch_stft_fb | 91 | |
480 | cuda | torch.float32 | librosa | librosa | 92 | |
480 | cuda | torch.float32 | asteroid | torch.stft | 92 | |
480 | cuda | torch.float32 | asteroid | stft_fb | 4 | |
480 | cuda | torch.float32 | asteroid | torch_stft_fb | 92 | |
480 | cuda | torch.float32 | asteroid | librosa | 92 | |
510 | cuda | torch.float32 | ones | torch.stft | 92 | |
510 | cuda | torch.float32 | ones | stft_fb | 24 | |
510 | cuda | torch.float32 | ones | torch_stft_fb | 92 | |
510 | cuda | torch.float32 | ones | librosa | 92 | |
510 | cuda | torch.float32 | librosa | torch.stft | 72 | |
510 | cuda | torch.float32 | librosa | stft_fb | 0 | |
510 | cuda | torch.float32 | librosa | torch_stft_fb | 73 | |
510 | cuda | torch.float32 | librosa | librosa | 90 | |
510 | cuda | torch.float32 | asteroid | torch.stft | 92 | |
510 | cuda | torch.float32 | asteroid | stft_fb | 3 | |
510 | cuda | torch.float32 | asteroid | torch_stft_fb | 92 | |
510 | cuda | torch.float32 | asteroid | librosa | 92 | |
511 | cuda | torch.float32 | ones | torch.stft | 92 | |
511 | cuda | torch.float32 | ones | stft_fb | 27 | |
511 | cuda | torch.float32 | ones | torch_stft_fb | 92 | |
511 | cuda | torch.float32 | ones | librosa | 92 | |
511 | cuda | torch.float32 | librosa | torch.stft | 66 | |
511 | cuda | torch.float32 | librosa | stft_fb | 0 | |
511 | cuda | torch.float32 | librosa | torch_stft_fb | 66 | |
511 | cuda | torch.float32 | librosa | librosa | 89 | |
511 | cuda | torch.float32 | asteroid | torch.stft | 91 | |
511 | cuda | torch.float32 | asteroid | stft_fb | 3 | |
511 | cuda | torch.float32 | asteroid | torch_stft_fb | 91 | |
511 | cuda | torch.float32 | asteroid | librosa | 92 |
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
import functools | |
import numpy as np | |
import torch | |
import librosa | |
from asteroid_filterbanks import make_enc_dec | |
from asteroid_filterbanks.stft_fb import STFTFB | |
from asteroid_filterbanks.torch_stft_fb import TorchSTFTFB | |
from asteroid.losses.sdr import singlesrc_neg_sisdr | |
def sisdr(target, pred): | |
target = target.cpu() | |
pred = pred.cpu() | |
return -singlesrc_neg_sisdr(pred[:len(target)][None], target[:len(pred)][None])[0] | |
def torch_roundtrip(x, win, hop): | |
stft = torch.stft(x, n_fft=len(win), window=win, hop_length=hop, return_complex=True) | |
return torch.istft(stft, n_fft=len(win), window=win, hop_length=hop) | |
def asteroid_roundtrip(cls, x, win, hop): | |
enc, dec = make_enc_dec(cls, window=win.cpu(), kernel_size=len(win), n_filters=len(win), stride=hop) | |
return dec.to(x)(enc.to(x)(x)) | |
stft_fb_roundtrip = functools.partial(asteroid_roundtrip, STFTFB) | |
torch_stft_fb_roundtrip = functools.partial(asteroid_roundtrip, TorchSTFTFB) | |
def librosa_roundtrip(x, win, hop): | |
win = win.cpu().numpy() | |
x = x.cpu().numpy() | |
return torch.from_numpy(librosa.istft(librosa.stft(x, len(win), hop, window=win), hop, window=win)) | |
wav = torch.from_numpy(...) | |
print("hop,dev,dtype,win,impl,error (dB)") | |
for hop in [32, 64, 128, 256, 384, 480, 510, 511]: | |
for win_name, win in [ | |
("ones", torch.ones(512)), | |
("librosa", torch.from_numpy(librosa.filters.get_window("hann", 512, fftbins=True))), | |
("asteroid", torch.from_numpy(np.hanning(513)[:-1]**0.5)), | |
]: | |
for dtype in [torch.float32]: | |
for dev in ["cuda"]: | |
for impl_name, impl in [ | |
("torch.stft", torch_roundtrip), | |
("stft_fb", stft_fb_roundtrip), | |
("torch_stft_fb", torch_stft_fb_roundtrip), | |
("librosa", librosa_roundtrip), | |
]: | |
wav = wav.to(dtype).to(dev) | |
print(hop, dev, dtype, win_name, impl_name, int(sisdr(wav, impl(wav, win.to(wav), hop)).item()), sep=",") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment