Error when using dropout and initial_state in gru layer
See original GitHub issuemy 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:
- Created 6 years ago
- Comments:7
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:
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.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.