0
$\begingroup$

According to the convolution theorem, convolution operation changes to pointwise multiplication in fourier domain - here I have 'fft_x' of shape (batchsize, height, width, in_channels) which is the fft of input data and similarly 'fft_kernel' of shape (height, width, in_channels, out_channels) which is fft of the kernel after being padded to image size. To get pointwise multiplication of these in efficient way, I was using einsum in the following way -

...
    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 
...

It gives the following output and error-

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

Could anyone please explain why this error is arising? Thanks in advance for any help.

$\endgroup$

1 Answer 1

1
$\begingroup$
import tensorflow as tf
output  = tf.einsum('ijkl,jklo->ijko', fft_x, fft_kernel)

I used tf.einsum instead of np.einsum, and it worked. Also as seen in above, I removed the loop and changed the equation in einsum.

$\endgroup$
2
  • $\begingroup$ It might be better to add some explanation. What is the tf? I don't see it as part of your code. Either try to explain or add more code for those that will come to this question in the future. $\endgroup$
    – Tasos
    Apr 1, 2019 at 8:34
  • $\begingroup$ Edited the answer. $\endgroup$
    – psj
    Apr 1, 2019 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.