Help with inference

#10
by AngryBear9019 - opened

Hello to everyone. I can't make it work no matter what I do. Can anyone help me solve the issue.
I am far from the python world of programming and if you can explain what is happening, can you please do it like you're explaining to a 5-year-old, thanks to any help in advance.
I am running the code on Windows 10...
So, I have installed all necessary libraries, here is the list that pip outputs:

certifi==2022.12.7
cffi==1.16.0
charset-normalizer==2.1.1   
colorama==0.4.6
filelock==3.9.0
fsspec==2024.3.1
huggingface-hub==0.21.4     
idna==3.4
Jinja2==3.1.2
MarkupSafe==2.1.3
mpmath==1.3.0
networkx==3.2.1
numpy==1.26.3
packaging==24.0
pandas==2.2.1
pillow==10.2.0
pycparser==2.21
python-dateutil==2.9.0.post0
pytz==2024.1
PyYAML==6.0.1
regex==2023.12.25
requests==2.28.1
six==1.16.0
soundfile==0.12.1
sympy==1.12
tokenizers==0.13.3
torch==2.2.0+cu118
torchaudio==2.2.0+cu118
torchvision==0.17.0+cu118
tqdm==4.66.2
transformers==4.28.0
typing_extensions==4.8.0
tzdata==2024.1
urllib3==1.26.13

I have copied the inference proposed on the page (Model Card with one modification there is a line: 151num_workers=10 I put a value to 0) and when running with an audio file I get an error when running the code.

D:\wav2vec2-large-xlsr-53-gender-recognition-librispeech\gender_pred\lib\site-packages\torch\nn\utils\weight_norm.py:28: UserWarning: torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm.
  warnings.warn("torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm.")
  0%|                                                                                                                                                                                                 | 0/1 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "D:\wav2vec2-large-xlsr-53-gender-recognition-librispeech\inference.py", line 175, in <module>
    preds = get_gender(model_name_or_path, audio_paths, label2id, id2label, device)
  File "D:\wav2vec2-large-xlsr-53-gender-recognition-librispeech\inference.py", line 153, in get_gender
    preds = predict(test_dataloader=test_dataloader, model=model, device=device)
  File "D:\wav2vec2-large-xlsr-53-gender-recognition-librispeech\inference.py", line 113, in predict
    for batch in tqdm.tqdm(test_dataloader):
  File "D:\wav2vec2-large-xlsr-53-gender-recognition-librispeech\gender_pred\lib\site-packages\tqdm\std.py", line 1181, in __iter__
    for obj in iterable:
  File "D:\wav2vec2-large-xlsr-53-gender-recognition-librispeech\gender_pred\lib\site-packages\torch\utils\data\dataloader.py", line 631, in __next__
    data = self._next_data()
  File "D:\wav2vec2-large-xlsr-53-gender-recognition-librispeech\gender_pred\lib\site-packages\torch\utils\data\dataloader.py", line 675, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
  File "D:\wav2vec2-large-xlsr-53-gender-recognition-librispeech\gender_pred\lib\site-packages\torch\utils\data\_utils\fetch.py", line 54, in fetch
    return self.collate_fn(data)
  File "D:\wav2vec2-large-xlsr-53-gender-recognition-librispeech\inference.py", line 89, in __call__
    input_tensor = self.processor(audio, sampling_rate=self.sampling_rate).input_values
  File "D:\wav2vec2-large-xlsr-53-gender-recognition-librispeech\gender_pred\lib\site-packages\transformers\models\wav2vec2\feature_extraction_wav2vec2.py", line 196, in __call__
    padded_inputs = self.pad(
  File "D:\wav2vec2-large-xlsr-53-gender-recognition-librispeech\gender_pred\lib\site-packages\transformers\feature_extraction_sequence_utils.py", line 169, in pad
    raise ValueError(
ValueError: type of {'input_values': array([0.00045148, 0.00109712, 0.00116506, ..., 0.        , 0.        ,
       0.        ], dtype=float32), 'attention_mask': None} unknown: <class 'dict'>. Should be one of a python, numpy, pytorch or tensorflow object.

Greetings,

I trust this message finds you well. Upon review, it appears the issue originated from the "transformers" library version (4.28.0) you are utilizing, which is more recent than the version used when the example code was initially developed. This discrepancy has led to differences in how input data is processed before being fed into the gender recognition model.

I have now updated the example code to be compatible with the current version of the "transformers" library. This update should resolve the error you were encountering. Please feel free to test the revised code and let us know if you face any further issues.

Best regards.

Hello @alefiury and I would like to THANK YOU for your work and quick response. Now everything works as expected and nothing fails! You are great.

I have another question, about the num_workers=2 if I don't use it at 0 I get an error and the inference fails. What does this param mean and how it should work? Thank you for your reply in advance.

Owner

Hello! It's great to hear that everything is working smoothly for you now.

The "num_workers" setting makes loading data faster by doing several tasks at once. But on Windows, you might need to set it to 0 because it can cause problems, and even though it's slower, it still works fine.

@alefiury thank you for your answer it's very helpful.

alefiury changed discussion status to closed

Sign up or log in to comment