adeshpande3 / LSTM-Sentiment-Analysis

Sentiment Analysis with LSTMs in Tensorflow
MIT License
984 stars 431 forks source link

Errors when running code on Mac #2

Open benallpass opened 7 years ago

benallpass commented 7 years ago

edit - I've downgraded TensorFlow from 1.2 to 1.1 and the issue no longer occurs

When running the section of code:

sess = tf.InteractiveSession()
saver = tf.train.Saver()
saver.restore(sess, tf.train.latest_checkpoint('models'))

I get the following errors:

tensorflow/core/framework/op_kernel.cc:1158] Not found: Key rnn/basic_lstm_cell/kernel/Adam_1 not found in checkpoint
tensorflow/core/framework/op_kernel.cc:1158] Not found: Key rnn/basic_lstm_cell/kernel/Adam not found in checkpoint
tensorflow/core/framework/op_kernel.cc:1158] Not found: Key rnn/basic_lstm_cell/bias not found in checkpoint
tensorflow/core/framework/op_kernel.cc:1158] Not found: Key rnn/basic_lstm_cell/bias/Adam not found in checkpoint
tensorflow/core/framework/op_kernel.cc:1158] Not found: Key rnn/basic_lstm_cell/bias/Adam_1 not found in checkpoint
tensorflow/core/framework/op_kernel.cc:1158] Not found: Key rnn/basic_lstm_cell/kernel not found in checkpoint

I'm on macOS 10.12 and have the same issue with both Python 3.5 and 3.6. It occurs when running python from command line or with jupyter.

adeshpande3 commented 7 years ago

Thanks for bringing this up. Currently not sure why this error is popping up, I'll look into it a bit more. But, like you said, a workaround is just to downgrade to 1.1 😢

sabriwi commented 7 years ago

Hi, I got similar errors when running this with TensorFlow 1.3 on Windows 7. For various reasons it wasn't feasible for me to downgrade to 1.1, but I think I found a workaround. My hypothesis is that there were some subtle or not so subtle changes between the different releases on how tf saves and stores models. I made it work for me on tf 1.3 by changing the following bits of code in your notebooks.

In the Oriole notebook, where you train the model, I changed the order of the last two lines from:

sess = tf.InteractiveSession()
saver = tf.train.Saver()
sess.run(tf.global_variables_initializer())

to:

sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver()

because I read somewhere that you have to initalise the variables before you initialise the saver.

Second, when trying to restore a model from an arbitrary checkpoint (not just the latest one, which seemed to work fine with the code suggested), the following code works for me:

saver = tf.train.Saver()
sess = tf.InteractiveSession()
saver = tf.train.import_meta_graph('models/XXX.ckpt-50000.meta')
saver.restore(sess, 'models/XXX.ckpt-50000')

I don't understand why, but the first line is essential and it won't work without.

Eurus-Holmes commented 6 years ago

I have also the same bug... how to solve it...

adeshpande3 commented 6 years ago

Take a look at this README section or try the Docker setup.