def create_lstm_autoencoder(input_dim, timesteps, latent_dim):
"""
Creates an LSTM Autoencoder (VAE). Returns Autoencoder, Encoder, Generator.
(All code by fchollet - see reference.)
# Arguments
input_dim: int.
timesteps: int, input timestep dimension.
latent_dim: int, latent z-layer shape.
# References
- [Building Autoencoders in Keras](https://blog.keras.io/building-autoencoders-in-keras.html)
"""
inputs = Input(shape=(timesteps, input_dim,))
encoded = LSTM(latent_dim)(inputs)
decoded = RepeatVector(timesteps)(encoded)
decoded = LSTM(input_dim, return_sequences=True)(decoded)
sequence_autoencoder = Model(inputs, decoded)
encoder = Model(inputs, encoded)
autoencoder = Model(inputs, decoded)
autoencoder.compile(optimizer='adam', loss='mse')
return autoencoder
评论列表
文章目录