keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.71k stars 19.43k forks source link

input_shape issue when stateful=True #1125

Closed ekerazha closed 8 years ago

ekerazha commented 8 years ago

I'm trying the stateful RNN implementation. This is my code:

model.add(GRU(hidden_neurons, input_dim=in_out_neurons, return_sequences=True, stateful=True, input_length=5))

But I get this error:

Exception: If a RNN is stateful, a complete input_shape must be provided (including batch size).

Please note that I provide both input_dim and input_length. I also tried to provide input_shape, but I got the same error. Moreover it says "including batch size", but there isn't any "batch_size" parameter.

In layers/recurrent.py there's this code:

    if self.stateful:
        if not input_shape[0]:
            raise Exception('If a RNN is stateful, a complete ' +
                            'input_shape must be provided ' +
                            '(including batch size).')

If I print input_shape I get (None, input_length, input_dim), so it raises an exception because input_shape[0] is "None". What is that first parameter?

fchollet commented 8 years ago

You can now use the keyword argument batch_input_shape to specify an input shape that includes the batch size. I'll fix the error message.

anujgupta82 commented 8 years ago

@fchollet : I am still getting this error despite using batch_input_shape

check cell 20 in this notebook https://github.com/anujgupta82/DeepNets/blob/master/LSTM/IMDB_Embedding_w2v_LSTM_3.ipynb

philipperemy commented 8 years ago

Have a look at that : http://philipperemy.github.io/keras-stateful-lstm/