相当于最新 PyTorch 版本中的 torch.rfft()
我想估计给定尺寸 BxCxWxH
的图像的傅里叶变换
在以前的 torch 版本中,以下工作完成了这项工作:
fft_im = torch.rfft(img, signal_ndim=2, onesided=False)
并且输出的大小为:
BxCxWxHx2
但是,使用新版本的 rfft :
fft_im = torch.fft.rfft2(img, dim=2, norm=None)
我不这样做得到相同的结果。我错过了什么吗?
I want to estimate the fourier transform for a given image of size BxCxWxH
In previous torch version the following did the job:
fft_im = torch.rfft(img, signal_ndim=2, onesided=False)
and the output was of size:
BxCxWxHx2
However, with the new version of rfft :
fft_im = torch.fft.rfft2(img, dim=2, norm=None)
I do not get the same results. Do I miss something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些问题
dim
参数是无效类型,它应该是两个数字的元组或者应该被省略。实际上 PyTorch 应该引发异常。我认为这无一例外地运行的事实是 PyTorch 中的一个错误(我开了一张票,说明了这一点)。complex
张量类型,因此 FFT 函数返回这些而不是为实部/虚部添加新的维度。您可以使用torch.view_as_real
转换为旧的表示形式。还值得指出的是,view_as_real 不会复制数据,因为它返回一个视图,因此不会以任何明显的方式减慢速度。因此,
如果您要将
fft_im
传递给torch.fft
中的其他函数(例如 < code>fft.ifft 或fft.fftshift
),那么您需要使用torch.view_as_complex
所以这些函数不要将最后一个维度解释为信号维度。A few issues
dim
argument you provided is an invalid type, it should be a tuple of two numbers or should be omitted. Really PyTorch should raise an exception. I would argue that the fact this ran without exception is a bug in PyTorch (I opened a ticket stating as much).complex
tensor types, so FFT functions return those instead of adding a new dimension for the real/imaginary parts. You can usetorch.view_as_real
to convert to the old representation. Also worth pointing out thatview_as_real
doesn't copy data since it returns a view so shouldn't slow things down in any noticeable way.torch.fft.fft2
, which is in conflict with the 13th aphorism of PEP 20. The whole point of providing a special real-valued version of the FFT is that you need only compute half the values for each dimension, since the rest can be inferred via the Hermition symmetric property.So from all that you should be able to use
Important If you're going to pass
fft_im
to other functions intorch.fft
(likefft.ifft
orfft.fftshift
) then you'll need to convert back to the complex representation usingtorch.view_as_complex
so those functions don't interpret the last dimension as a signal dimension.