python - Keras LSTM 中的多层隐藏层

标签 python deep-learning keras keras-layer

x = Input(shape=(timesteps, input_dim,))

# LSTM encoding
h = LSTM(2048)(x)

这是我从互联网下载的文件中的几行代码。我认为 h 适用于具有 2048 个单元的单层 LSTM 层。它如何使其成为多层,即 2 个隐藏层。

最佳答案

只需添加另一层(我们称之为g)!但由于我们要传递到另一个 LSTM 层,因此我们必须将 return_sequences 关键字参数添加到第一层,以便我们可以获得正确的输入形状第二层。

x = Input(shape=(timesteps, input_dim,))

# LSTM encoding
h = LSTM(2048, return_sequences=true)(x)
g = LSTM(10)(h)

关于python - Keras LSTM 中的多层隐藏层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45726422/

相关文章:

python - 如何找到深度学习模型的大小?

python - 更改 Keras 中的输入大小

python - Keras属性错误: 'History' object has no attribute 'predict'

python - 当我在 tensorflow.keras 中使用 BinaryCrossentropy(from_logits=True) 时,我应该使用什么作为目标向量

python - 将连续映射到连续的强化学习方法

javascript - 相当于javascript中python的uuid.uuid4().hex?

python - 从亚马逊获取所有评论? python 3

python - Tensorflow hub.load 模型到 TFLite

python - 如何在Keras中实现CRelu?

python - Numpy 将 3d 矩阵乘以 2d 矩阵