У объекта «List» нет атрибута 'Shape' Speechbrain PythonPython

Программы на Python
Anonymous
 У объекта «List» нет атрибута 'Shape' Speechbrain Python

Сообщение Anonymous »

Я столкнулся с ошибкой при использовании библиотеки Speechbrain со следующим сообщением:

Код: Выделить всё

Error during encoding: 'list' object has no attribute 'shape'

контекст:

Я работаю над распознаванием динамиков, используя модель Speakerseconcognition . Ниже приведен код, который я использую: < /p>

Код: Выделить всё

import numpy as np
from speechbrain.pretrained import SpeakerRecognition

# Initialize the speaker recognition model
model = SpeakerRecognition.from_hparams(
source="speechbrain/spkrec-ecapa-voxceleb",
savedir="pretrained_model"
)

# Path to the WAV file
wav_file = r"c:\audio_files\test.wav"  # Update with your file path

# Test the model encoding using the encode_batch method
try:
# The model expects input as a list of file paths
embeddings = model.encode_batch([wav_file])

# Check the returned embeddings' structure
if embeddings:
print("Embeddings received successfully.")

# Check if the embeddings are tensors or NumPy arrays
if hasattr(embeddings[0], 'cpu'):  # If it's a tensor
first_embedding = embeddings[0].cpu().numpy()  # Convert to NumPy array
print("First embedding converted to NumPy array.")
elif isinstance(embeddings[0], np.ndarray):  # If it's already a NumPy array
first_embedding = embeddings[0]
print("First embedding is already a NumPy array.")

# Display the shape of the first embedding if it's a NumPy array
if isinstance(first_embedding, np.ndarray):
print("Shape of the first embedding:", first_embedding.shape)
else:
print("The embedding is neither a tensor nor a NumPy array.")
else:
print("No embeddings returned or empty list.")
except Exception as e:
print(f"Error during encoding: {e}")
< /code>
[h4] Проблема: < /h4>
Проблема, по -видимому, возникает при проверке формы встраивания. В частности, это выглядит как Enterdings [0] 
- это список вместо тензора или массива Numpy.
Вопрос: [/h4]
  • Почему я получаю ошибку «Список». Объект «нет атрибута» ? encode_batch < /code> для извлечения их формы? Я новичок в речевых и на основе Python ML Frameworks. Любое разъяснение или руководство будет оценено!


Подробнее здесь: https://stackoverflow.com/questions/793 ... ain-python

Вернуться в «Python»