Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torchaudio #4

Closed
HudsonHuang opened this issue Nov 26, 2020 · 4 comments
Closed

torchaudio #4

HudsonHuang opened this issue Nov 26, 2020 · 4 comments

Comments

@HudsonHuang
Copy link

Nice work.
But it seems there're already resample implemented by conv1d in pytorch's official torchaudio
Is there any necessary to implement it again?

@adefossez
Copy link
Owner

First this project is a DSP hobby, so I'm quite happy to reimplement things that already exists.
From your question I decided to run a quick comparison. First in terms of speed, torchaudio seems to be slower, at least on CPU. I guess it is because it does multiple calls to conv1d followed conv_transpose1d, while julius has a single call to conv1d. I will open up a bug report to torchaudio on that issue.

from torchaudio.compliance import kaldi
import torch
import julius
x = th.randn(1, 44100 * 10)
rolloff = 0.99  # lowpass filter freq used by torchaudio
zeros = 6  # use the same number of zero crossing as torchaudio
for from_sr, to_sr in [(5, 7), (7, 5)]:
    print("comparing for", from_sr, to_sr)
    %timeit kaldi.resample_waveform(x, from_sr, to_sr)
    %timeit julius.resample_frac(x, from_sr, to_sr, rolloff=rolloff, zeros=zeros)
    yt = kaldi.resample_waveform(x, from_sr, to_sr)
    yj = julius.resample_frac(x, from_sr, to_sr, rolloff=rolloff, zeros=zeros)
    print(torch.norm(yt - yj))
comparing for 5 7
32.4 ms ± 309 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
4.46 ms ± 44.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
tensor(8.7085e-05)
comparing for 7 5
12.9 ms ± 323 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
2.83 ms ± 43.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
tensor(5.1333e-05)

Julius implementation is also shorter in terms of code.

@adefossez
Copy link
Owner

Bug report opened pytorch/audio#1057

@HudsonHuang
Copy link
Author

Great, I agree that we can learn a lot to re-implement something, and it would be even better as share your idea to benefit the whole community. Thank you.

@adefossez
Copy link
Owner

The implementation from julius is now part of Torchaudio: pytorch/audio#1087 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants