Reputation: 181
I'm trying to run a simple convolution but with complex numbers:
r = np.random.random([1,10,10,10])
i = np.random.random([1,10,10,10])
x = tf.complex(r,i)
conv_layer = tf.layers.conv2d(
inputs=x,
filters=10,
kernel_size=[3,3],
kernel_initializer=utils.truncated_normal_complex(),
activation=tf.nn.sigmoid)
However I get this error:
TypeError: Value passed to parameter 'input' has DataType complex128 not in list of allowed values: float16, float32
Does anyone know how to implement such a convolution in Tensorflow?
Will I need to implement a custom op, or is there some better option here?
Frustratingly, complex matrix multiplication is possible, e.g. the following runs fine:
def r():
return np.random.random([10,10])
A = tf.complex(r(),r())
B = tf.complex(r(),r())
C = tf.multiply(A,B)
sess.run(C)
So there's no real reason convolution shouldn't work, I would think (as convolution is essentially just matrix multiplication).
Thanks
Upvotes: 5
Views: 2865
Reputation: 989
You can perform complex convolution by breaking up your tensors into real and imaginary parts. If x=a+bi and y=c+di then xy = ac-bd + i*(bc+ad). Similarly, you can break up your tensors into real and imaginary parts and convolve each part separately. Pseudo code:
A_real = tf.math.real(A)
A_imag = tf.math.imag(A)
B_real = tf.math.real(B)
B_imag = tf.math.imag(B)
AB_conv_real = convolve(A_real, B_real) - convolve(A_imag, B_imag)
AB_conv_imag = convolve(A_real, B_imag) + convolve(A_imag, B_real)
Upvotes: 0
Reputation: 428
All complex-valued features are split into either Cartesian (real, imaginary) or polar (modulus, angle) representations. Nobody is really trying to use a single feature that is purely complex; I would love to be proven wrong!
Upvotes: 0
Reputation: 1
Probably too late but for anyone who still is interested: applying convolutions to complex valued data is not as straightforward as your usual data types, like float32. There are studies that investigat different network structures for this purpose (for example see this link for "Deep Complex U-Net"). There are implementations of these structures in pytorch and tensorflow.
Upvotes: 0