visionml / pytracking

Visual tracking library based on PyTorch.
GNU General Public License v3.0
3.19k stars 603 forks source link

How to deal with "module 'torch' has no attribute 'rfft'" #383

Closed faicaiwawa closed 1 year ago

faicaiwawa commented 1 year ago

ninja: no work to do. Loading extension module _prroi_pooling... /home/qiuyang/.conda/envs/pytracking/lib/python3.8/site-packages/torch/nn/functional.py:3451: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details. warnings.warn( module 'torch' has no attribute 'rfft' Done

I found that this fault is caused by the pytorch version update, I found that this problem can be solved by inserting code, but I am a newbie, can you tell me how to solve this error,thankyou!

faicaiwawa commented 1 year ago

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

The reason for this problem is that pytorch removed torch.rfft in 1.80, I tried to use the above code to fix this error, after fixing the code can run but does not trace properly. Non-NVIDIA 30 series users can directly reduce the pytorch version, 30 series users please use pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html note: must use pip, conda install will make a cublas problem