question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when using dropout and initial_state in gru layer

See original GitHub issue

my code is: _costs_embd = TimeDistributed( Dense(costs_embd_size, kernel_initializer=RandomUniform(-0.08, 0.08)))(costs) _search_1 = GRU(h_search, return_sequences=True, kernel_initializer=RandomUniform(-0.08, 0.08), dropout=dropout)(_costs_embd, initial_state=[state_h]) The error shown is: Traceback (most recent call last): File "main.py", line 21, in <module> dropout=0.2) File "/home/hazem/PycharmProjects/optimizer-memory-network/optimzernet.py", line 50, in build_agent _costs_embd, initial_state=[state_h]) File "/usr/local/lib/python2.7/dist-packages/keras/layers/recurrent.py", line 519, in __call__ output = super(RNN, self).__call__(full_input, **kwargs) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 603, in __call__ output = self.call(inputs, **kwargs) File "/usr/local/lib/python2.7/dist-packages/keras/layers/recurrent.py", line 1503, in call self.cell._generate_dropout_mask(inputs, training=training) File "/usr/local/lib/python2.7/dist-packages/keras/layers/recurrent.py", line 1268, in _generate_dropout_mask ones = K.ones_like(K.squeeze(inputs[:, 0:1, :], axis=1)) TypeError: list indices must be integers, not tuple Removing dropout or initial_state argument seems to solve the problem but you can’t use them both Any help on this issue ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
LitleCarlcommented, Dec 4, 2017

As a simple workaround, go ahead to pip package source and make the change:

In file: xxx/site-packages/keras/layers/recurrent.py

In method:

  • _generate_recurrent_dropout_mask
  • _generate_dropout_mask

Insert the code into the first line of the methods:

if type(inputs) is list:
            inputs = inputs[0]

When you specify initial_state, the actual input becomes (samples, state_1, state_2…), but we only need the first element representing train data here.

0reactions
beatrizalbierocommented, Aug 16, 2018

Hi @LitleCarl, how can i change the keras source code? I tried but when I ran my code again (after restarting my kernel) it seemed to me that my changes were inefficient.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TesorFlow Keras GRU layer invalid argument error - 'expected ...
So I found a solution that seems to work for me. When I call model.input I get the following output that suggests that...
Read more >
tf.keras.layers.GRU | TensorFlow v2.11.0
This argument is passed to the cell when calling it. This is only relevant if dropout or recurrent_dropout is used (optional, defaults to...
Read more >
Working with RNNs - Keras
To configure a RNN layer to return its internal state, set the return_state parameter to True when creating the layer. Note that LSTM...
Read more >
10 Hyperparameters to keep an eye on for your LSTM model
LSTMs enable backpropagation of the error through time and layers hence ... Every LSTM layer should be accompanied by a dropout layer.
Read more >
Introduction to Recurrent Networks in TensorFlow
Recurrent networks like LSTM and GRU are powerful sequence models. ... of one or more layers, the cell type and possibly dropout between...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found