I want to create stateful LSTM in keras. I gave it a command like this:
model.add(LSTM(300,input_dim=4,activation='tanh',stateful=True,batch_input_shape=(19,13,4),return_sequences=True))
where batch size=19. But on running it gives error
Exception: In a stateful network, you should only pass inputs with a number of samples that can be divided by the batch size. Found: 8816 samples. Batch size: 32.
I did not specify batch size 32 anywhere in my script and 19 is divisible by 8816
model.fit()
does the batching (as opposed to model.train_on_batch
for example). Consequently it has a batch_size
parameter which defaults to 32.
Change this to your input batch size and it should work as expected.
Example:
batch_size = 19
model = Sequential()
model.add(LSTM(300,input_dim=4,activation='tanh',stateful=True,batch_input_shape=(19,13,4),return_sequences=True))
model.fit(x, y, batch_size=batch_size)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With