D:\zhaoxiaobai\conda\envs\audio\python.exe "D:/audio_deep learning/dataset/class dataset.py" Traceback (most recent call last): File "D:/audio_deep learning/dataset/class dataset.py", line 10, in <module> waveform,sample_rate = torchaudio.load(filepath) File "D:\zhaoxiaobai\conda\envs\audio\lib\site-packages\torchaudio\backend\soundfile_backend.py", line 221, in load with soundfile.SoundFile(filepath, "r") as file_: File "D:\zhaoxiaobai\conda\envs\audio\lib\site-packages\soundfile.py", line 658, in __init__ self._file = self._open(file, mode_int, closefd) File "D:\zhaoxiaobai\conda\envs\audio\lib\site-packages\soundfile.py", line 1216, in _open raise LibsndfileError(err, prefix="Error opening {0!r}: ".format(self.name)) soundfile.LibsndfileError: Error opening 'D:\\audio_deep learning\\hole.wav': Format not recognised.
时间: 2023-06-30 21:23:32 浏览: 329
根据错误提示,您的音频文件 'D:\\audio_deep learning\\hole.wav' 的格式无法被识别。可以尝试以下方法解决问题:
1. 确认音频文件格式:使用其他工具(例如Audacity)打开音频文件,确认它的格式是否为torchaudio支持的格式(如wav、mp3、flac、ogg等)。
2. 安装依赖库:您需要安装所需的依赖库,例如libsndfile(libavformat/libavcodec)等,以支持更多的音频格式。具体方法可以参考torchaudio官方文档。
3. 尝试转换音频格式:如果您确认音频文件格式正确,但仍无法加载,请尝试使用其他工具将音频文件转换为torchaudio支持的格式,例如使用ffmpeg等。
如果以上方法仍无法解决问题,请提供更多信息和错误提示,以便更好地帮助您解决问题。
相关问题
TypeError: Caught TypeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "/root/ConvNeXt/my_dataset.py", line 40, in __getitem__ img = self.transform(a) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 95, in __call__ img = t(img) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 952, in forward i, j, h, w = self.get_params(img, self.scale, self.ratio) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 913, in get_params width, height = F.get_image_size(img) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torchvision/transforms/functional.py", line 76, in get_image_size return F_pil.get_image_size(img) File "/root/miniconda3/envs/py38/lib/python3.8/site-packages/torchvision/transforms/functional_pil.py", line 27, in get_image_size raise TypeError(f"Unexpected type {type(img)}") TypeError: Unexpected type <class 'numpy.ndarray'>
这个错误是由于在 DataLoader 的 worker 进程中,数据集中的某个样本在进行 transform 时出现了错误。具体来说,是由于 get_image_size 函数期望的 PIL.Image 对象被传入了一个 numpy 数组。你可以检查一下数据集中的这个样本,看看是否正确加载,并且检查一下 transform 中是否使用了正确的数据类型。
Exception in thread Thread-6: Traceback (most recent call last): File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dataloader/dataloader_iter.py", line 218, in _thread_loop self._thread_done_event) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dataloader/fetcher.py", line 125, in fetch data.append(self.dataset[idx]) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlenlp/datasets/dataset.py", line 96, in __getitem__ idx]) if self._transform_func else self.data[idx] File "/tmp/ipykernel_857/3798068411.py", line 20, in convert_example label = label_map[label] KeyError: 2
这个错误提示是在执行数据集迭代时出现的。根据错误提示信息,可以看到在执行 `convert_example` 函数时,出现了 `KeyError: 2` 错误,这是因为数据集中出现了一个不存在于标签映射表中的标签值。
因此,需要检查标签映射表是否正确,以及数据集中是否存在标签映射表中没有包含的标签值。可以通过打印标签映射表和数据集中的标签值来进行排查,例如:
```python
label_map = {'label1': 0, 'label2': 1}
for data, label in dataset:
if label not in label_map:
print('Invalid label:', label)
```
另外,还需要检查 `convert_example` 函数是否正确实现了标签映射功能,确保每个标签值都可以正确地映射到对应的数字标签。
阅读全文