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.

reset_states() failure in a stateful network with initial_states set and training in batch - TypeError: 'NoneType' object is not subscriptable

See original GitHub issue

Following is the stacktrace -

Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/manoj/Desktop/repos/yane/yane/LSTM/manytomanyLSTM.py", line 137, in <module>
    incremental_train(space)
  File "/Users/manoj/Desktop/repos/yane/yane/LSTM/manytomanyLSTM.py", line 128, in incremental_train
    model.reset_states()
  File "/usr/local/lib/python3.6/site-packages/keras/engine/topology.py", line 1968, in reset_states
    layer.reset_states()
  File "/usr/local/lib/python3.6/site-packages/keras/layers/recurrent.py", line 681, in reset_states
    batch_size = self.input_spec[0].shape[0]        
TypeError: 'NoneType' object is not subscriptable

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
huancommented, Feb 21, 2019

I ran into this issue today with TF 2.0 preview.

Raised an issue at https://github.com/tensorflow/tensorflow/issues/25985

1reaction
manojregecommented, Sep 15, 2018

Steps to reproduce: If the initial_states is removed, the code works.

from keras.models import Input, Model
from keras.layers import Dense, LSTM

epochs = 1
trainY = np.random.rand(32 * 32, 1)

interleaved_trainX = np.random.rand(32 * 32, 1, 1)
interleaved_trainY = np.random.rand(32 * 32, 1, 1)

encoder_inputs = Input(batch_shape=(32, 1, 1), name='ENCODER_INPUT')
encoder = LSTM(256,
               return_sequences=True,
               stateful=True,
               name='LSTM',
               return_state=True)
encoder_outputs, state_h, state_c = encoder(encoder_inputs)
encoder_states = [state_h, state_c]

decoder_inputs = Input(batch_shape=(32, 1, 1),
                       name='DECODER_INPUT')
decoder = LSTM(256,
               return_sequences=True,
               stateful=True,
               name='DECODER_LSTM')
decoder_out = decoder(decoder_inputs, initial_state=encoder_states)
decoder_2 = LSTM(256,
                 return_sequences=False,
                 stateful=True,
                 batch_size=32,
                 name='DECODER_LSTM2')(decoder_out)
decoder_outputs = Dense(1, name='DENSE')(decoder_2)

model = Model([encoder_inputs, decoder_inputs], decoder_outputs)

model.compile(loss='mse', optimizer='adam', metrics=['mean_absolute_percentage_error'])
for i in range(epochs):
    print('Epoch', i, '/', epochs)
    model.fit([interleaved_trainX, interleaved_trainY], trainY,
              batch_size=32,
              validation_data=([interleaved_trainX, interleaved_trainY], trainY),
              verbose=1,
              epochs=1,
              shuffle=False)
    model.reset_states()

loss, mape = model.evaluate([interleaved_trainX, interleaved_trainY],
                            trainY,
                            batch_size=32,
                            verbose=1)

print('Test accuracy:', loss)
print('Test MAPE:', mape)
Read more comments on GitHub >

github_iconTop Results From Across the Web

reset_states() failure in a stateful network with initial_states ...
reset_states() failure in a stateful network with initial_states set and training in batch - TypeError: 'NoneType' object is not subscriptable #25985.
Read more >
"TypeError: 'NoneType' object is not subscriptable" I'm ...
"TypeError: 'NoneType' object is not subscriptable" I'm having trouble fixing this problem. building a neural network in python.
Read more >
Python TypeError: 'NoneType' object is not subscriptable
If you try to access an item from a None value using indexing, you encounter a “TypeError: 'NoneType' object is not subscriptable” error....
Read more >
CS50AI TICTACTOE - 'NoneType' object is not subscriptable
I've been reading through my codes, although i know where my error is, i do not know how to go about solving it....
Read more >
Time Series Analysis: KERAS LSTM Deep Learning - Part 1
Learn time series analysis with Keras LSTM deep learning. Learn to predict sunspots ten years into the future with an LSTM deep learning ......
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