python中numpy函数fft_如何在PyTorch中正确使用Numpy的FFT函数?

我最近被介绍给Pythorch,开始浏览图书馆的文档和教程。

在“使用numpy和scipy创建扩展”教程中(

http://pytorch.org/tutorials/advanced/numpy_extensions_tutorial.html),在“无参数示例”下,使用名为“BadFFTFunction”的numpy创建一个示例函数。在

功能说明如下:"This layer doesn’t particularly do anything useful or mathematically

correct.

It is aptly named BadFFTFunction"

函数及其用法如下:from numpy.fft import rfft2, irfft2

class BadFFTFunction(Function):

def forward(self, input):

numpy_input = input.numpy()

result = abs(rfft2(numpy_input))

return torch.FloatTensor(result)

def backward(self, grad_output):

numpy_go = grad_output.numpy()

result = irfft2(numpy_go)

return torch.FloatTensor(result)

def incorrect_fft(input):

return BadFFTFunction()(input)

input = Variable(torch.randn(8, 8), requires_grad=True)

result = incorrect_fft(input)

print(result.data)

result.backward(torch.randn(result.size()))

print(input.grad)

不幸的是,我也是最近才被介绍信号处理的,我不确定(可能是明显的)这个函数的错误在哪里。在

我想知道,如何修复这个函数,使它的正向和反向输出都是正确的?

如何固定BadFFTFunction以便在PyTorch中使用可微FFT函数?在

任何帮助都将不胜感激。

谢谢您。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值