AttributeError: module ‘torch‘ has no attribute ‘irfft‘ ‘rfft‘‘

Cause Analysis

The source code was written in a version before torch1.7, and my own environment is above torch1.7. The original torch.rfft and torch.rfft were deleted by torch upgrade, and they cannot be called.

Solution

Downgrade the torch version without reinstalling the environment! ! ! ! !

Just change the function interface

Search for places where torch.rfft and torch.irfft are used
Add the following code at the top of the file. At the same time, change torch.rfft to rfft and torch.irfft to irfft

try:
    from torch import irfft
    from torch import rfft
except ImportError:
    from torch.fft import irfft2
    from torch.fft import rfft2
    def rfft(x, d):
        t = rfft2(x, dim = (-d,-1))
        return torch.stack((t.real, t.imag), -1)
    def irfft(x, d, signal_sizes):
        return irfft2(torch.complex(x[:,:,0], x[:,:,1]), s = signal_sizes, dim = (-d,-1))

Guess you like

Origin blog.csdn.net/qq_35608277/article/details/129169689