Can we use tf.spectral fourier functions in keras?

前端 未结 4 1699
清酒与你
清酒与你 2021-02-06 16:56

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

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-06 17:04

    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)
    

提交回复
热议问题