0
我想建立一個使用Keras的LSTM網絡。 我的時間seriese例子的大小爲492
。我想用3
前面的例子來預測下一個例子。因此,輸入轉換爲尺寸(num_samples,3*492)
,輸出尺寸爲(num_samples,492)
。建立與keras LSTM的尺寸錯誤
據this blog,我首先將我的數據大小爲形式的(num_samples,時間步長,功能)
#convert trainning data to 3D LSTM shape
train_origin_x = train_origin_x.reshape((train_origin_x.shape[0],3,492))
test_origin_x = test_origin_x.reshape((test_origin_x.shape[0],3,492))
print(train_origin_x.shape,test_origin_x.shape)
(216, 3, 492) (93, 3, 492)
print(train_origin_y,test_origin_y)
(216, 492) (93, 492)
而下面是我的代碼來構建LSTM網絡
#building network
model = Sequential()
model.add(LSTM(hidden_units,return_sequences=True,input_shape=(train_origin_x.shape[1],train_origin_x.shape[2])))
model.add(Dense(492))
model.compile(loss='mse',optimizer='adam')
print('model trainning begins...')
history = model.fit(train_origin_x,train_origin_y,epochs = num_epochs,batch_size = num_batchs,
validation_data=(test_origin_x,test_origin_y))
然而我在過程中遇到錯誤,說
ValueError: Error when checking target: expected dense_1 to have 3 dimensions, but got array with shape (216, 492)
任何kn ows問題是什麼?
任何意見或建議,歡迎和讚賞!
下面是model.summary()
model.summary()
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm_1 (LSTM) (None, 3, 50) 108600
_________________________________________________________________
dense_1 (Dense) (None, 3, 492) 25092
=================================================================
我試過,但還是得到了同樣的錯誤@Paddy –
對不起我的壞,檢查答案,去現在工作 – Paddy