LSTM 的 output_dim 怎么可能与下一层的 input_dim 不同?
How can a LSTM have an output_dim different than the input_dim of the next layer?
我在看这段代码:
model = Sequential()
model.add(LSTM(input_shape = (1,), input_dim=1, output_dim=6, return_sequences=True))
model.add(LSTM(input_shape = (1,), input_dim=1, output_dim=6, return_sequences=False))
model.add(Dense(1))
model.add(Activation('linear'))
第一层如何输出dim=6,然后下一层输出input_dim=1?
编辑
代码错误,Keras 只是尽力而为,如实际生成的模型所示(查看模型如何与代码不匹配):
这段代码非常混乱,绝对不应该这样写。
在顺序模型中,Keras 仅尊重第一层的input_shape
。所有后续层都使用上一层的输出进行初始化,有效地忽略了 input_shape
规范。源代码:keras/models.py
。在这种情况下,它是 (None, None, 6)
.
模型摘要如下所示:
Layer (type) Output Shape Param #
=================================================================
lstm_1 (LSTM) (None, None, 6) 192
_________________________________________________________________
lstm_2 (LSTM) (None, 6) 312
=================================================================
顺便说一下,keras 会针对此 LSTM
规范发出警告,因为 input_dim
已弃用:
Update your LSTM
call to the Keras 2 API: LSTM(input_shape=(None, 1), return_sequences=True, units=6)
Update your LSTM
call to the
Keras 2 API: LSTM(input_shape=(None, 1), return_sequences=False, units=6)
我在看这段代码:
model = Sequential()
model.add(LSTM(input_shape = (1,), input_dim=1, output_dim=6, return_sequences=True))
model.add(LSTM(input_shape = (1,), input_dim=1, output_dim=6, return_sequences=False))
model.add(Dense(1))
model.add(Activation('linear'))
第一层如何输出dim=6,然后下一层输出input_dim=1?
编辑
代码错误,Keras 只是尽力而为,如实际生成的模型所示(查看模型如何与代码不匹配):
这段代码非常混乱,绝对不应该这样写。
在顺序模型中,Keras 仅尊重第一层的input_shape
。所有后续层都使用上一层的输出进行初始化,有效地忽略了 input_shape
规范。源代码:keras/models.py
。在这种情况下,它是 (None, None, 6)
.
模型摘要如下所示:
Layer (type) Output Shape Param #
=================================================================
lstm_1 (LSTM) (None, None, 6) 192
_________________________________________________________________
lstm_2 (LSTM) (None, 6) 312
=================================================================
顺便说一下,keras 会针对此 LSTM
规范发出警告,因为 input_dim
已弃用:
Update your
LSTM
call to the Keras 2 API:LSTM(input_shape=(None, 1), return_sequences=True, units=6)
Update your
LSTM
call to the Keras 2 API:LSTM(input_shape=(None, 1), return_sequences=False, units=6)