UserWarning: amplitude_to_db was called on complex input so phase information will be discarded. To suppress this warning, call amplitude_to_db(np.abs(S)) instead. librosa.display.specshow(librosa.amplitude_to_db(C, ref=np.max), sr=sr, x_axis='time', y_axis='cqt_note') Traceback (most recent call last): File "D:\eda\789.py", line 16, in <module> plt.colorbar(format='%+2.0f dB')
时间: 2024-02-25 14:59:01 浏览: 22
这个警告是因为在使用`librosa.amplitude_to_db`函数时传入了复数的数据,因此相位信息将被舍弃。为了避免这个警告,你可以使用`np.abs`函数将CQT变换的结果转换为幅度谱,并将其传递给`librosa.amplitude_to_db`函数。修改代码如下:
```
import librosa
import librosa.display
import matplotlib.pyplot as plt
import numpy as np
# 读取音频文件
audio_file = 'example.wav'
y, sr = librosa.load(audio_file, sr=None)
# 计算CQT变换
C = librosa.cqt(y, sr=sr)
# 可视化CQT
plt.figure(figsize=(10, 4))
librosa.display.specshow(librosa.amplitude_to_db(np.abs(C), ref=np.max), sr=sr, x_axis='time', y_axis='cqt_note')
plt.colorbar(format='%+2.0f dB')
plt.title('CQT')
plt.tight_layout()
plt.show()
```
这样就可以避免警告,并正确绘制出CQT变换的可视化图像了。
相关问题
UserWarning: amplitude_to_db was called on complex input so phase information will be discarded. To suppress this warning, call amplitude_to_db(np.abs(S)) instead. CQT = librosa.amplitude_to_db(librosa.cqt(y, sr = 16000 ), ref = np. max )
这个警告表示amplitude_to_db函数被用在了复杂输入上,因此相位信息将被丢弃。为了避免这个警告,可以将输入转换成绝对值后再调用amplitude_to_db函数,即使用amplitude_to_db(np.abs(S))代替amplitude_to_db(S)。这样可以保留能量信息并且避免丢失相位信息。因此,可以将第6行修改为以下代码:
```
CQT = librosa.amplitude_to_db(np.abs(librosa.cqt(y, sr=16000)), ref=np.max)
```
这样就可以避免UserWarning了。
UserWarning: Failed to load image Python extension: libtorch_cuda_cu.so: cannot open shared object file: No such file or directory
这个警告是由于无法加载torchvision库中的图像处理模块所导致的。警告信息中提到了libtorch_cuda_cu.so文件找不到。这可能是由于缺少相关的依赖库或者环境配置不正确所致。
解决这个问题的方法有以下几种:
1. 确保安装了正确的torchvision版本。可以使用以下命令升级或重新安装torchvision:
```shell
pip install --upgrade torchvision
```
2. 检查是否安装了正确的CUDA驱动程序。如果你使用的是GPU版本的torchvision,需要安装与你的CUDA版本相匹配的驱动程序。
3. 检查是否安装了正确的CUDA工具包。可以使用以下命令安装与你的CUDA版本相匹配的工具包:
```shell
conda install cudatoolkit=<CUDA版本号>
```
4. 检查是否安装了正确的PyTorch版本。torchvision是PyTorch的一个扩展库,需要与PyTorch版本相匹配。可以使用以下命令升级或重新安装PyTorch:
```shell
pip install --upgrade torch
```
如果以上方法都无法解决问题,可能需要检查系统环境变量和库路径配置是否正确,并确保相关的依赖库已正确安装。