根据卷积定理,卷积运算在傅里叶域变为逐点乘法—— 这里我有'fft_x'的形状(批量大小,高度,宽度,in_channels)这是输入数据的fft 和类似的形状(高度,宽度,in_channels,out_channels)的'fft_kernel',它是填充到图像大小后内核的fft。为了以有效的方式对这些进行逐点乘法,我按以下方式使用了 einsum -
...
print(fft_x)
print(fft_kernel)
output = 0
n=int(self.no_of_kernels/2)+1 # n = out_channels here
for i in range(n):
output += np.einsum('ijkl,jkl->ijk', fft_x, fft_kernel[i])
return output
...
它给出以下输出-
Tensor("input_11:0", shape=(?, 28, 28, 1), dtype=complex64)
Tensor("fourier__conv2d_11/transpose:0", shape=(28, 28, 1, 17), dtype=complex64)
...
...
ValueError: einstein sum subscripts string contains too many subscripts for operand 0
谁能解释一下为什么会出现这个错误?在此先感谢您的帮助。
请您参考如下方法:
我使用的是 tf.einsum 而不是 np.einsum,它起作用了。
