Reputation: 179
I am following the code written in the tutorial here. I have followed exactly each line, but I am receiving the following error. Following is the error, followed by my code.
ValueError: Cannot evaluate tensor using
eval()
: No default session is registered. Usewith sess.as_default()
or pass an explicit session toeval(session=sess)
X = tf.placeholder(tf.float32, [None, n_timesteps, n_inputs])
basic_cell = tf.contrib.rnn.BasicRNNCell(num_units=n_neurons)
outputs, states = tf.nn.dynamic_rnn(basic_cell, X, dtype=tf.float32)
init = tf.global_variables_initializer()
# #with tf.Session() as sess:
sess = tf.Session()
with sess.as_default():
init.run()
sess.run(tf.global_variables_initializer())
outputs_val = outputs.eval(feed_dict={X: X_batch})
print(states.eval(feed_dict={X: X_batch}))
Upvotes: 1
Views: 891
Reputation: 515
You have to have an active session for the print line. Bring it under the with sess.as_default() as shown below.
Use the following
> with sess.as_default():
> init.run()
> sess.run(tf.global_variables_initializer())
> outputs_val = outputs.eval(feed_dict={X: X_batch})
> print(states.eval(feed_dict={X: X_batch}))
Upvotes: 2