簡體   English   中英

Keras Layer LSTM中的輸入不兼容

[英]Incompatible input in Keras Layer LSTM

我正在嘗試在Keras的網站上復制示例

# 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'  

LSTM層作為默認選項必須僅返回序列中的最后一個輸出。 這就是為什么您的數據失去其連續性的原因。 為了改變那個嘗試:

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

是什么使LSTM返回完整的預測序列。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM