Let us start with an input that is a simple time series and try to build an autoencoder that simply fourier transforms then untransforms our data in keras.
If we try to
I stumbled upon this as I was trying to solve the same problem. You can make the transition lossless by wrapping tf.real
and tf.imag
into Lambda
layers (I'm using stft
because there's no real valued equivalent):
x = tf.keras.layers.Lambda(
lambda v: tf.signal.stft(
v,
frame_length=1024,
frame_step=256,
fft_length=1024,
), name='gen/FFTLayer')(inputs)
real = tf.keras.layers.Lambda(tf.real)(x)
imag = tf.keras.layers.Lambda(tf.imag)(x)
...
# transform real and imag either separately or by concatenating them in the feature space.
...
x = tf.keras.layers.Lambda(lambda x: tf.complex(x[0], x[1]))([real, imag])
x = tf.keras.layers.Lambda(
lambda v: tf.signal.inverse_stft(
v,
frame_length=1024,
frame_step=256,
fft_length=1024,
))(x)