首页 > 解决方案 > AttributeError:模块“torch.fft”没有属性“fftfreq”

问题描述

我遵循了 https://pytorch.org/docs/stable/generated/torch.fft.fftshift.html#torch.fft.fftshift中的示例

import torch.fft
f = torch.fft.fftfreq(4)
a = torch.fft.fftshift(f)
print(a)

并得到了错误

AttributeError:模块“torch.fft”没有属性“fftfreq”

我尝试了 pip torch==1.7.0+cu110 和 pip torch==1.7.1+cu110 以及 conda pytorch==1.7.1 和 cudatoolkit=11.0。其他人也有同样的问题https://discuss.pytorch.org/t/unable-to-use-correctly-the-new-torch-fft-module/104560/6 但是改成torch1.7.0并没有解决问题.

如何正确使用 torch.fft?

标签: pythonpytorchfft

解决方案


函数torch.fft.fftfreq是在PyTorch 版本 1.8.0中引入的。您需要升级到此版本或更高版本才能使用它。


推荐阅读