4
我能夠使用keras成功地訓練我的有狀態LSTM。我的批量大小爲60,每輸入我在網絡中發送是的batch_size 以下整除是我的片斷:由於batch_size問題,有狀態LSTM無法預測
model = Sequential()
model.add(LSTM(80,input_shape = trainx.shape[1:],batch_input_shape=(60,
trainx.shape[1], trainx.shape[2]),stateful=True,return_sequences=True))
model.add(Dropout(0.15))
model.add(LSTM(40,return_sequences=False))
model.add(Dense(40))
model.add(Dropout(0.3))
model.add(Dense(output_dim=1))
model.add(Activation("linear"))
keras.optimizers.RMSprop(lr=0.005, rho=0.9, epsilon=1e-08, decay=0.0)
model.compile(loss="mse", optimizer="rmsprop")
我的訓練線,成功運行:
model.fit(trainx[:3000,:],trainy[:3000],validation_split=0.1,shuffle=False,nb_epoch=9,batch_size=60)
現在我試圖預測在測試集上可以再被60整除,但是我得到的錯誤:
ValueError: In a stateful network, you should only pass inputs with a number of samples that can be divided by the batch size. Found: 240 samples. Batch size: 32.
有誰能告訴我上面有什麼問題嗎?我很困惑,嘗試了很多東西,但沒有任何幫助。
謝謝,我認爲模型會記住批量大小是顯而易見的 – Harshit