【问题标题】:Incompatible input in Keras Layer LSTMKeras 层 LSTM 中的不兼容输入
【发布时间】:2017-08-05 17:03:22
【问题描述】:

我正在尝试复制example on Keras's website

# as the first layer in a Sequential model
model = Sequential()
model.add(LSTM(32, input_shape=(10, 64)))
# now model.output_shape == (None, 32)
# note: `None` is the batch dimension.

# for subsequent layers, no need to specify the input size:
model.add(LSTM(16))

但是当我运行以下命令时:

# only lines I've added: 
from keras.models import Sequential    
from keras.layers import Dense, LSTM  

# all else is the same: 
model = Sequential()
model.add(LSTM(32, input_shape=(10, 64)))
model.add(LSTM(16))

但是,我得到以下信息:
ValueError: Input 0 is incompatible with layer lstm_4: expected ndim=3, found ndim=2

版本:

Keras:      '2.0.5'  
Python:     '3.4.3'  
Tensorflow: '1.2.1'  

【问题讨论】:

  • 我的回答对你有帮助吗?

标签: python-3.x tensorflow neural-network keras keras-layer


【解决方案1】:

LSTM 层作为其默认选项,必须仅返回序列的最后一个输出。这就是为什么您的数据会失去其顺序性。为了改变这种尝试:

model.add(LSTM(32, input_shape=(10, 64), return_sequences=True))

是什么让LSTM 返回整个预测序列。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-18
    • 2020-10-25
    • 2021-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-06
    • 2019-03-26
    相关资源
    最近更新 更多