question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Torchaudio resampling could be faster and simpler

See original GitHub issue

🐛 Bug

I have been implementing a few DSP algorithms lately, including sinc based resampling. The following implementation could simplify the code in torchaudio and is also faster (single call to conv1d, instead of multiple calls to conv1d and conv_transpose1d). I’ll be happy to open a pull requests if you are interested.

https://github.com/adefossez/julius/blob/main/julius/resample.py

To Reproduce

Steps to reproduce the behavior:

  1. Install modules pip install -U torch torchaudio julius
  2. Run the benchmark code hereafter
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))

Expected behavior

Would expect torchaudio to be as fast as julius, results are

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)

Environment

  • What commands did you used to install torchaudio (conda/pip/build from source)? pip
  • If you are building from source, which commit is it?
  • What does torchaudio.__version__ print? 0.7.0a0+ac17b64

PyTorch version: 1.7.0 Is debug build: True CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A

OS: macOS 10.15.7 (x86_64) GCC version: Could not collect Clang version: 11.0.0 CMake version: version 3.18.4

Python version: 3.8 (64-bit runtime) Is CUDA available: False CUDA runtime version: No CUDA GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA HIP runtime version: N/A MIOpen runtime version: N/A

Versions of relevant libraries: [pip3] numpy==1.19.2 [conda] blas 1.0 mkl [conda] mkl 2019.4 233 [conda] mkl-service 2.3.0 py38hfbe908c_0 [conda] mkl_fft 1.2.0 py38hc64f4ea_0 [conda] mkl_random 1.1.1 py38h959d312_0 [conda] numpy 1.19.1 py38h3b9f5b6_0 [conda] numpy-base 1.19.1 py38hcfb5961_0 [conda] pytorch 1.7.0 py3.8_0 pytorch [conda] torchaudio 0.7.0 py38 pytorch

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
mogwaicommented, Dec 2, 2020

I’m not an expert in resampling by any means but I created a quick benchmark for speed and compared Log Spectral Distance and the Noise Ratio between slower more high quality methods in a notebook that might be useful for this thread

tldr; julius seems to be the best option

1reaction
vincentqbcommented, Jan 25, 2021

Thanks again for working on this 😃 I see #1087 as closing this issue. If this is not the case, please feel free to re-open, or if there are follow-ups, to open new issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Audio Resampling — PyTorch Tutorials 1.13.1+cu117 ...
This tutorial shows how to use torchaudio's resampling API. ... and a variety of parameters can be used to control for its quality...
Read more >
Simple Audio Augmentation with PyTorch | Jonathan Bgn
The idea is simple: by applying random transformations to your training examples, you can generate new examples for free and make your training ......
Read more >
torchaudio load audio with specific sampling rate
Resample can be used from transforms. waveform, sample_rate = torchaudio.load('test.wav', normalize=True) transform = transforms.
Read more >
Audio manipulation with torchaudio - PyTorch Tutorials
In this tutorial, we will look into how to prepare audio data and extract ... f'{resample}']) return torchaudio.sox_effects.apply_effects_file(path, ...
Read more >
Getting Started With Torchaudio | PyTorch Tutorial - YouTube
Your browser can 't play this video. ... data - Transformations - Resampling - Data Augmentation - Feature Extraction - Torchaudio Datasets ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found