首先明确一点,RNN单元的输入输出的维度,点击参考keras.layers.RNN()文档
输入尺寸
3D 张量,尺寸为 (batch_size, timesteps, input_dim)。
输出尺寸
- 如果 return_state:返回张量列表。 第一个张量为输出。剩余的张量为最后的状态, 每个张量的尺寸为 (batch_size, units)。
- 如果 return_sequences:返回 3D 张量, 尺寸为 (batch_size, timesteps, units)。
- 否则,返回尺寸为 (batch_size, units) 的 2D 张量。
每层LSTM的输入是前一层的LSTM的输出,所以自第二层LSTM开始,input_shape参数是可以忽略的
以双层的LSTM为例
#参数
time_steps = 10
features = 2
input_shape = [time_steps, features]
batch_size = 32
model = Sequential()
model.add(LSTM(64, input_shape=input_shape, return_sequences=True))
model.add(LSTM(32,input_shape=input_shape))
model.summary()
>>>
Model: "sequential_1"
_________________________________________________________________
Layer (type) Output Shape Param #
========

本文深入解析RNN和LSTM的输入输出维度,通过实例展示如何在Keras中搭建多层LSTM网络,解释units参数的真实含义,以及如何通过调整参数影响模型输出。
14万+

被折叠的 条评论
为什么被折叠?



