AttributeError: module 'torch' has no attribute 'rfft' with PyTorch
I am getting an error using a code that should work according to the documentation.
The goal is to calculate the Feature Similarity Index Measure (FSIM) using the piq Python library.
Terminal Output:
TiffPage 1: ByteCounts tag is missing
Traceback (most recent call last):
  File &quot;...\.venv\lib\site-packages\IPython\core\interactiveshell.py&quot;, line 3441, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File &quot;&lt;ipython-input-2-3044cfc208ce&gt;&quot;, line 1, in &lt;module&gt;
    runfile('.../stackoverflow.py', wdir='...')
  File &quot;...\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py&quot;, line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File &quot;...\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py&quot;, line 18, in execfile
    exec(compile(contents+&quot;\n&quot;, file, 'exec'), glob, loc)
  File &quot;.../stackoverflow.py&quot;, line 15, in &lt;module&gt;
    main()
  File &quot;...\.venv\lib\site-packages\torch\autograd\grad_mode.py&quot;, line 27, in decorate_context
    return func(*args, **kwargs)
  File &quot;.../stackoverflow.py&quot;, line 10, in main
    fsim_index: torch.Tensor = piq.fsim(x, y, data_range=1., reduction='none')
  File &quot;...\.venv\lib\site-packages\piq\fsim.py&quot;, line 84, in fsim
    pc_x = _phase_congruency(
  File &quot;...\.venv\lib\site-packages\piq\fsim.py&quot;, line 241, in _phase_congruency
    imagefft = torch.rfft(x, 2, onesided=False)
AttributeError: module 'torch' has no attribute 'rfft'

Code:
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__ == &quot;__main__&quot;:
    main()


The latest version of pytorch implements all fast fourier functions in the module torch.fft, apparently piq rely on an older version of pytorch, so if you want to run piq consider downgrading your pytorch version, for example:
pip3 install torch==1.7.1 torchvision==0.8.2 


