python-3.x 属性错误:模块“torch”没有PyTorch属性“rfft”

v64noz0r  于 2023-05-19  发布在  Python
关注(0)|答案(3)|浏览(766)

我得到了一个错误,使用的代码应该根据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()
xdyibdwo

xdyibdwo1#

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

pip3 install torch==1.7.1 torchvision==0.8.2

wribegjk

wribegjk2#

您可以使用torch.fft.rfft代替torch.rfft。

kpbwa7wx

kpbwa7wx3#

试试下面的安装

pip install torch==1.3.1

或小于1.7

pip install torch==1.7.1

相关问题