1 回答

TA貢獻1804條經驗 獲得超2個贊
上面的示例返回 shape (1, 480, 16)。當您設置 時return_sequences=True,Keras 將返回時間步維度(您的“中間”維度),因此如果您的輸入有 480 個時間步,它將輸出 480 個時間步。最后一個維度將是最后一層中的單元數。
import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import *
model = Sequential()
model.add(LSTM(32, input_shape=(480, 16), return_sequences = True))
model.add(Dense(16))
model.compile(loss='mse', optimizer='adam')
batch = np.zeros((90, 480, 16))
input_to_predict = batch[[0]]
model.predict(input_to_predict).shape
array([[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]]], dtype=float32)
(1, 480, 16)
如果設置return_sequences=False,它不會返回時間步長維度:
import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import *
model = Sequential()
model.add(LSTM(32, input_shape=(480, 16), return_sequences = False))
model.add(Dense(16))
model.compile(loss='mse', optimizer='adam')
batch = np.zeros((90, 480, 16))
input_to_predict = batch[[0]]
model.predict(input_to_predict).shape
(1, 16)
添加回答
舉報