[英]How to properly specify an input shape for a LSTM model in Keras
假設我們有一個Numpy數組,其中包含整數。
arr = [1, 2, 3]
我們有一個Keras模型。
model.add(LSTM(128, input_shape=(arr)))
如何正確指定輸入形狀?
LSTM層的輸入數據必須是三維的,並且形狀為(num_samples, timesteps, num_features)
。
您為LSTM圖層指定的input_shape
具有形狀(timesteps, num_features)
。 input_shape
並不關心樣本數量,僅關心每個樣本的形狀。
如果我們假設timesteps=1
,那么您想要做這樣的事情。
arr = np.array([1, 2, 3])
arr.shape # (3,)
arr = arr.reshape(arr.shape[0], 1, 1)
arr.shape # (3, 1, 1)
model.add(LSTM(128, input_shape=(arr.shape[1], arr.shape[2])))
在timesteps=1
使用LSTM並沒有多大意義,但希望您能理解。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.