Can we use tf.spectral fourier functions in keras?

前端 未结 4 1702
清酒与你
清酒与你 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:28

    Just to add more to what's going on above for anyone who gets here from search engines. The following, contributed in this google group discussion, will run rfft then ifft with convolutions and other layers in between:

    inputs = Input(shape=(10, 8), name='main_input')
    x = Lambda(lambda v: tf.to_float(tf.spectral.rfft(v)))(inputs)
    x = Conv1D(filters=5, kernel_size=3, activation='relu', padding='same')(x)
    x = Lambda(lambda v: tf.to_float(tf.spectral.irfft(tf.cast(v, dtype=tf.complex64))))(x)
    x = Flatten()(x)
    output = Dense(1)(x)
    model = Model(inputs, output)
    model.summary()
    

    It uses the same concepts as Allen's answer but the slight differences allow compatibility with intermediate convolutions.

提交回复
热议问题