qiuqiangkong / torchlibrosa

MIT License
450 stars 45 forks source link

Torch / Torchlibrosa dependency issue #12

Open arbelhizmi opened 1 year ago

arbelhizmi commented 1 year ago

I have a container that contain the following packages:

python = "3.9.6"
librosa = "0.8.0"
torch = "1.9.0+cu111"
torchaudio = "0.9.0"
torchlibrosa = "0.0.9"

When I change the versions torch, torchaudio to:

python = "3.9.6"
librosa = "0.8.0"
torch = "1.10.0+cu111"
torchaudio = "0.10.0"
torchlibrosa = "0.0.9"

I receive the following error:

UNAVAILABLE: Internal: TypeError: pad_center() takes 1 positional argument but 2 were given
At:
/usr/local/lib/python3.8/dist-packages/torchlibrosa/stft.py(193): __init__
/usr/local/lib/python3.8/dist-packages/torchlibrosa/stft.py(645): __init__

It seems like torchlibrosa=0.0.9 has some problem with torch=1.10.0+cu111. Another problem is that in according to the documentation torchlibrosa=0.0.9 (or torchlibrosa in general) is not depends on any torch version. According to the setup.py file (https://github.com/qiuqiangkong/torchlibrosa/blob/master/setup.py) these are the required packages:

install_requires=[
        'numpy',
        'librosa>=0.9.0'
    ]

No torch version is required. When I open new environment that only has torchlibrosa=0.0.9 installed in it and run the example from the REAME file:

import torch
import torchlibrosa as tl

batch_size = 16
sample_rate = 22050
win_length = 2048
hop_length = 512
n_mels = 128

batch_audio = torch.empty(batch_size, sample_rate).uniform_(-1, 1)  # (batch_size, sample_rate)

# TorchLibrosa feature extractor the same as librosa.feature.melspectrogram()
feature_extractor = torch.nn.Sequential(
    tl.Spectrogram(
        hop_length=hop_length,
        win_length=win_length,
    ), tl.LogmelFilterBank(
        sr=sample_rate,
        n_mels=n_mels,
        is_log=False, # Default is true
    ))
batch_feature = feature_extractor(batch_audio) # (batch_size, 1, time_steps, mel_bins)

The following error is raised:

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'torch'

To conclude, it seems like there two problems:

  1. The documentation of torchlibrosa doesn't mention torch as a "must" requirement even though it should be a must requirement
  2. There is a problem with torchlibrosa=0.0.9 that is working with torch=1.10.0+cu111
Abdul-Melik commented 1 year ago

Any update on this? I have the same error relating to the pad_center function, i have torch 1.11.0 and torchlibrosa 0.0.9.