question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

module 'torch' has no attribute 'rfft'

See original GitHub issue

When I try to run the example, I get a runtime error

>>> X = dct.dct(x)   # DCT-II done through the last dimension
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/torch_dct/_dct.py", line 48, in dct
    Vc = torch.rfft(v, 1, onesided=False)
AttributeError: module 'torch' has no attribute 'rfft'

my torch version is ‘1.10.2+cu113’. Did I miss something?

Also, I want to ask what is scaled DCT? Does the input of scaled DCT need to be in range [0,1]?

Thank you very much!

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

18reactions
MaloShadycommented, Jun 22, 2022

Found the solution hidden in another post: https://github.com/zh217/torch-dct/issues/15#issuecomment-851439294

To migrate the DCT code to the newest pytorch version, you only have to change two lines; one in dct, one in idct.

dct:

#Vc = torch.rfft(v, 1, onesided=False)           # comment this line
Vc = torch.view_as_real(torch.fft.fft(v, dim=1))  # add this line

idct:

# v = torch.irfft(V, 1, onesided=False)                             # comment this line
v= torch.fft.irfft(torch.view_as_complex(V), n=V.shape[1], dim=1)   # add this line

Took me wayyy too long to figure out. Hope it helps you!

0reactions
jonnorcommented, Nov 7, 2022

This can be closed now. Fixed in PR https://github.com/zh217/torch-dct/pull/24

Read more comments on GitHub >

github_iconTop Results From Across the Web

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...
Read more >
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...
Read more >
Fourier transform in latest pytorch - vision
fft_src = torch.rfft(src_img.clone(), signal_ndim=2, onesided=False). The error: AttributeError: module 'torch' has no attribute 'rfft'.
Read more >
解决报错:AttributeError: module 'torch' has no attribute 'irfft'
解决报错:AttributeError: module 'torch' has no attribute 'irfft' ... try: from torch import irfft from torch import rfft except ...
Read more >
旧版pytorch中torch.rfft和irfft在新版本中的对应 - 知乎专栏
pytorch旧版本(1.7之前)中有一个函数torch.rfft(),但是新版本(1.8、1.9)中被 ... 是安装1.7之前版本的pytorch,也会出现module 'torch' has no attribute 'rfft'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found