I am building a CNN where the input is a grayscale image (256x256x1) and I want to add a Fourier transform layer which should output a shape (256x256x2), with the 2 channels for real and imaginary. I found tf.signal.fft2d on https://www.tensorflow.org/api_docs/python/tf/signal/fft2d . Unfortunately it is hard to find any example or explanation of how to use it concretely... I have tried:
X_input = Input(input_shape,)
X_input_fft=Lambda(lambda v: tf.cast(tf.compat.v1.spectral.rfft2d(v),dtype=tf.float32))(X_input)
l1Conv1 = Conv2D(filters = 16, kernel_size = (5,5), strides = 1, padding ='same',
data_format='channels_last',
kernel_initializer= initializers.he_normal(seed=None),
bias_initializer='zeros')(X_input_fft)
but honestly I don't know what I am doing ...
Also, for the last layer, I would like to do an inverse fft, something like:
myLastLayer= Lambda(lambda v: tf.cast(tf.compat.v1.spectral.irfft2d(tf.cast(v, dtype=tf.complex64)),dtype=tf.float32))(myBeforeLastLayer)