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

speechbrain inference classifier error #2457

Open
JGanson opened this issue Mar 11, 2024 · 1 comment
Open

speechbrain inference classifier error #2457

JGanson opened this issue Mar 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@JGanson
Copy link

JGanson commented Mar 11, 2024

Describe the bug

problem appears on the speechbrain.inference.classifiers

when run classify_batch, the self.mods report "AttributeError: 'ModuleDict' object has no attribute 'compute_features'"

dient_checkpointingto a config initialization is deprecated and will be removed in v5 Transformers. Usingmodel.gradient_checkpointing_enable()instead, or if you are using theTrainerAPI, passgradient_checkpointing=Truein yourTrainingArguments`.
warnings.warn(
speechbrain.lobes.models.huggingface_transformers.huggingface - Wav2Vec2Model is frozen.
Traceback (most recent call last):
File "C:\Users\JGanson\Desktop\DeepLearning\ASR\code\torch\wav2vec_speechbrain.py", line 18, in
prediction = model.classify_batch(signal)
File "C:\Users\JGanson\anaconda3\envs\nlp\lib\site-packages\speechbrain\inference\classifiers.py", line 249, in classify_batch
X_stft = self.mods.compute_stft(wavs)
File "C:\Users\JGanson\anaconda3\envs\nlp\lib\site-packages\torch\nn\modules\module.py", line 1614, in getattr
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'ModuleDict' object has no attribute 'compute_stft

Expected behaviour

my code just simple loading the pretrained model and run, so it shouldn't get this bug

To Reproduce

from speechbrain.inference.classifiers import AudioClassifier
import numpy as np
import torch

Load the pre-trained model

model = AudioClassifier.from_hparams(source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP", savedir="tmpdir")
data = np.load("data/IEMOCAP_audio.npy",allow_pickle=True).item()
model.hparams.label_encoder.ignore_len()

audio = data['audio']

input = audio[0]

signal = torch.tensor(input)

signal = signal.unsqueeze(0) # Add a batch dimension

prediction = model.classify_batch(signal)

Environment Details

torch 2.0.1+cu117 pypi_0 pypi
torchaudio 2.0.2+cu117 pypi_0 pypi
torchvision 0.15.2+cu117 pypi_0 pypi
speechbrain 1.0.0 pypi_0 pypi

Relevant Log Output

No response

Additional Context

No response

@JGanson JGanson added the bug Something isn't working label Mar 11, 2024
@TParcollet
Copy link
Collaborator

Hi, the reason for this error is that you are not using the correct inference class to use speechbrain/emotion-recognition-wav2vec2-IEMOCAP. This model, as you can see from the code snippet here uses a specific feature of speechbrain inference -- custom inferences. When a model requires a custom inference that cannot be generalised to a usefull class. we allow users or the maintainers to add a custom inference.py You can find this inference if you naviguate into the files of the HuggingFace repo.

Note to developpers:
This model was done by @aheba I don't know if he is still around and would like to, instead, integrate this as a standard inference in our lobes. I think it should be there to be honest. I think wav2vec2 or SSL bases classifier should have their own inference class in lobes. @Adel-Moumen, adding this to your infinite to-do list?

@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants