0

我正在尝试实现频域 ReLu,详见:http ://cs231n.stanford.edu/reports/2015/pdfs/tema8_final.pdf

令我困惑的公式在第 4 页的左下角。我不确定我是否正确计算了 dirac 函数的 FFT 之和。我是否错误地解释了这个公式?

import numpy as np
import matplotlib.pyplot as plt

img = np.array([[-1.0,2.3],[5,7.8]])

# Dirac is essentially the shifting matrix
# So create the 2d shifting matrix values
N = 2
x = np.arange(0, N, 1)
y = np.arange(0, N, 1)
xm, ym = np.meshgrid(x, y)
shiftMat = np.exp(1j * ((2.0 * np.pi)) * (xm + ym))

# Set equal to shift mat
# In this trivial example I know that [0,0] is only negative position
# So set to 0 and compute sum of all positions in which f(x) > 0 as detailed in paper
freqRelu = shiftMat
freqRelu[0,0] = 0
freqRelu = np.sum(freqRelu)

# Fourier Convolution and IFFT
imgFFT = np.fft.fft2(img)
freqR = np.multiply(imgFFT,freqRelu)
reluedFreq = np.real(np.fft.ifft2(freqR))

# Spatial Relu For Comparision
reluedImg = img
reluedImg[0,0] = 0

plt.subplot(121)
plt.imshow(reluedImg)
plt.subplot(122)
plt.imshow(reluedFreq)
plt.show()

print(np.allclose(reluedFreq,reluedImg))
print(reluedFreq)
print(reluedImg)
4

1 回答 1

0

作为参考,这里的信号堆栈交换回答了这个问题:https ://dsp.stackexchange.com/questions/49023/sum-of-diracs-in-frequency-domain

于 2018-06-14T19:51:57.383 回答