2017-05-05 38 views
2

假設我有一個隨時間變化的特徵矢量,並希望這個矢量映射到單個矢量以用作分類中的圖層。 Keras將如何實施?例如:使用Keras中的LSTM將矢量序列映射到單個矢量

Input: <1.0, 2.0, 3.0> -> <1.1, 1.9, 3.2> -> ... 
Output: <1.0, 0.0, 0.0, 2.0> 

的Keras文檔說,LSTM對象發生在3個維度,但我不知道怎麼表達,在這種情況下。

回答

1

LSTM需要輸入[batch_size, time_steps, input_dim]。在你的情況下,你可以把每個向量作爲一個時間步。因此,在兩個時間步輸入將是:

[<1.0, 2.0, 3,0>, <1.1, 1.0, 3.2>] which maps to <1.0, 0.0, 0.0, 2.0> 

舉個例子:

input_dim = 3 
num_steps = 2 

model = Sequential() 
model.add(LSTM(16, input_shape=(num_steps, input_dim)) # output 2d [batch_size, 16] 
model.add(Dense(4)) # output [batch, 4] 

# ... more layers 

不要害怕看他們做的很好的文檔。 https://keras.io/layers/recurrent/#lstm

+1

我很難理解LSTM的....在這個例子中,LSTM層的輸出形狀是什麼? –

+0

我添加了一些註釋代碼。 – putonspectacles