1 回答

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
您在處理時(shí)間維度時(shí)遇到形狀不匹配...當(dāng)您嘗試預(yù)測(cè)時(shí)間維度為 2 的內(nèi)容時(shí),時(shí)間輸入 dim 為 1。因此您的網(wǎng)絡(luò)中需要一些能夠從 1 增加到 2 時(shí)間的東西方面。我使用了Upsampling1D圖層,下面是一個(gè)完整的例子
# create fake data
X = np.random.uniform(0,1, (98,1,2))
Y = np.random.uniform(0,1, (98,2,1))
verbose, epochs, batch_size = 1, 20, 16
n_neurons = 100
n_inputs, n_features = X.shape[1], X.shape[2]
n_outputs = Y.shape[1]
model = Sequential()
model.add(LSTM(n_neurons, input_shape = (n_inputs, n_features), return_sequences=True))
model.add(UpSampling1D(n_outputs))
model.add(TimeDistributed(Dense(1)))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(X, Y, epochs=epochs, batch_size=batch_size, verbose=verbose)
輸入時(shí)間暗淡 > 輸出時(shí)間暗淡,您可以使用 Lambda 或 Pooling 操作(如果維度匹配)。下面是一個(gè)使用 Lambda 的例子
X = np.random.uniform(0,1, (98,3,2))
Y = np.random.uniform(0,1, (98,2,1))
verbose, epochs, batch_size = 1, 20, 16
n_neurons = 100
n_inputs, n_features = X.shape[1], X.shape[2]
n_outputs = Y.shape[1]
model = Sequential()
model.add(LSTM(n_neurons, input_shape = (n_inputs, n_features), return_sequences=True))
model.add(Lambda(lambda x: x[:,-n_outputs:,:]))
model.add(TimeDistributed(Dense(1)))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(X, Y, epochs=epochs, batch_size=batch_size, verbose=verbose)
添加回答
舉報(bào)