Ricky
Ricky

Reputation: 2750

Where is RNN is taking batch size from?

I am training a RNN by by below :

def create_rnn_model(stateful,length):
    model = Sequential()
    model.add(SimpleRNN(20,return_sequences=False,stateful=stateful,batch_input_shape=(1,length,1)))
    adam = optimizers.Adam(lr=0.001)
    model.add(Dense(1))
    model.compile(loss='mean_absolute_error', optimizer=adam, metrics=[root_mean_squared_error])
    print(model.summary())
    return model

and the fit by

model_info = model_rnn_stateful.fit(x=x_train, y=y_train, validation_data=(x_test, y_test), batch_size=1, epochs=10,verbose=1)

and predict by

predicted_rnn_stateful = model_rnn_stateful.predict(x_test)

But when I predict it throws an error

ValueError: In a stateful network, you should only pass inputs with a number of samples that can be divided by the batch size. Found: 200 samples. Batch size: 32.

There is no where I specify 32. I don't know where it is coming from.My batch size is 1 only.Any help is appreciated.

EDIT I have no breakpoints used in my script/IDE.Thank you

Upvotes: 0

Views: 83

Answers (1)

Mael Galliffet
Mael Galliffet

Reputation: 166

From Keras documentation

  • batch_size: Integer or None. Number of samples per gradient update. If unspecified, batch_size will default to 32.

1 is probably an incorrect value for batch_size, then it took the default value which is 32. Try with 2 or 20 as batch_size

Upvotes: 1

Related Questions