python - 属性错误 : module 'torch' has no attribute 'rfft' with PyTorch

标签 python python-3.x image image-processing pytorch

我在使用应根据 documentation 工作的代码时遇到错误. 目标是使用 piq Python 库计算特征相似性指数度量 (FSIM)。

终端输出:

TiffPage 1: ByteCounts tag is missing
Traceback (most recent call last):
  File "...\.venv\lib\site-packages\IPython\core\interactiveshell.py", line 3441, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-3044cfc208ce>", line 1, in <module>
    runfile('.../stackoverflow.py', wdir='...')
  File "...\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "...\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File ".../stackoverflow.py", line 15, in <module>
    main()
  File "...\.venv\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File ".../stackoverflow.py", line 10, in main
    fsim_index: torch.Tensor = piq.fsim(x, y, data_range=1., reduction='none')
  File "...\.venv\lib\site-packages\piq\fsim.py", line 84, in fsim
    pc_x = _phase_congruency(
  File "...\.venv\lib\site-packages\piq\fsim.py", line 241, in _phase_congruency
    imagefft = torch.rfft(x, 2, onesided=False)
AttributeError: module 'torch' has no attribute 'rfft'

代码:

from skimage import io
import torch
import piq

@torch.no_grad()
def main():
    x = torch.tensor(io.imread('scikit_image\cover\cover_1.tiff')).permute(2, 0, 1)[None, ...] / 255.
    y = torch.tensor(io.imread('scikit_image\stego\stego_1.tiff')).permute(2, 0, 1)[None, ...] / 255.

    fsim_index: torch.Tensor = piq.fsim(x, y, data_range=1., reduction='none')

    print(fsim_index)

if __name__ == "__main__":
    main()

最佳答案

最新版本的pytorch在模块torch.fft中实现了所有快速傅里叶函数,显然piq依赖于旧版本的pytorch,所以如果你想运行piq可以考虑降级你的pytorch版本,例如:

pip3 install torch==1.7.1 torchvision==0.8.2 

enter image description here

关于python - 属性错误 : module 'torch' has no attribute 'rfft' with PyTorch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67647299/

相关文章:

python - 如何将 TrainingArguments 对象转换为 json 文件?

javascript - 将 JavaScript JSON 数据转换为 Python JSON

python - Python 中 super().__init__() 和显式父类(super class) __init__() 之间的行为差​​异

python 类在 __init__ 中使用 super 调用自身

c# - 通过 http post 发送 base64 String 最终在 C# 中为空服务器端

css - 在居中页面上显示带边框的图像

python - 使用值(例如 0)初始化嵌套列表

python-3.x - 值错误: check_hostname requires server_hostname using Fiddler 4

algorithm - 将图像包裹在 3d 对象周围以便于 2d 打印

python - Keras seq2seq - 词嵌入