speechbrain icon indicating copy to clipboard operation
speechbrain copied to clipboard

speechbrain.inference is not working

Open underdogliu opened this issue 1 year ago • 4 comments

Describe the bug

I am now trying to call the Sepformer based on this tutorial from Hugging Face. But after installing the toolkit according to the instruction, seems like it cannot be properly run.

Expected behaviour

After running the script according to the instruction, speechbrain.inference cannot be properly called with simple error

ModuleNotFoundError: No module named 'speechbrain.inference'

To Reproduce

On Colab, first run

!git clone https://github.com/speechbrain/speechbrain.git
!cd speechbrain && pip install -r requirements.txt && pip install -e .

Then run

from speechbrain.inference.separation import SepformerSeparation as separator
from speechbrain.inference.interfaces import fetch
from speechbrain.inference.metrics import SNREstimator as snrest

import torchaudio

# 1- Download a test mixture
fetch("test_mixture.wav", source="speechbrain/sepformer-wsj02mix", savedir=".", save_filename="test_mixture.wav")

# 2- Separate the mixture with a pretrained model (sepformer-whamr in this case)
model = separator.from_hparams(source="speechbrain/sepformer-whamr", savedir='pretrained_models/sepformer-whamr')
est_sources = model.separate_file(path='test_mixture.wav')

# 3- Estimate the performance
snr_est_model = snrest.from_hparams(source="speechbrain/REAL-M-sisnr-estimator",savedir='pretrained_models/REAL-M-sisnr-estimator')
mix, fs = torchaudio.load('test_mixture.wav')
snrhat = snr_est_model.estimate_batch(mix, est_sources)
print(snrhat) # Estimates are in dB / 10 (in the range 0-1, e.g., 0 --> 0dB, 1 --> 10dB)

Environment Details

Google colab default environment Speechbrain version: 1.0.0 (installed from source)

Relevant Log Output

No response

Additional Context

No response

underdogliu avatar Jul 31 '24 06:07 underdogliu

Hey @underdogliu, to solve this issue, either place code file where you are using "speechbrain" inside "speechbrain" folder cloned from Github or simply change from speechbrain.inference.separation import SepformerSeparation as separator to from speechbrain.speechbrain.inference.separation import SepformerSeparation as separator and similar changes to every import you are doing.

The issue is arising because "inference" folder is present in such path: speechbrain>speechbrain>inference. Please let me know if this solves your issue.

malayjoshi13 avatar Aug 23 '24 06:08 malayjoshi13

@asumagic this has been fixed in 1.0.1, right?

TParcollet avatar Sep 06 '24 08:09 TParcollet

@asumagic this has been fixed in 1.0.1, right?

No, unrelated. As hinted above, I think the problem is just that the setup for this colab makes it so that a speechbrain directory is cloned in the working directory. When Python then tries to import it, the environment's speechbrain package path /foo/bar/speechbrain/speechbrain/ is shadowed by the local directory, i.e. /foo/bar/speechbrain/.

This is just a Python quirk, and I don't think it's a SB bug, rather just wrong commands in the colab that should be fixed. I would be surprised if it ever worked.

asumagic avatar Sep 06 '24 10:09 asumagic

... We could maybe detect this situation by adding an __init__.py to the main repo that would just error out with a hint, but that could be a source of confusion for whoever checks the repo and might have unintended consequences.

asumagic avatar Sep 06 '24 11:09 asumagic