0
# Build a graph.
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b

# Launch the graph in a session.
sess = tf.compat.v1.Session()

# Evaluate the tensor `c`.
print(sess.run(c))

This above code is taken from tensorflow core r2.0 documentation But it gives the above error

Krishna Rohith
  • 74
  • 1
  • 1
  • 11

1 Answers1

0

The thing is

The tensorflow core r2.0 have enabled eager execution by default so doesn't need to write tf.compat.v1.Session() and use .run() function If we want to use tf.compat.v1.Session() then we need to do thi tf.compat.v1.disable_eager_execution() in the starting of algorithm. Now we can use tf.compat.v1.Session() and .run() function.

Tensorflow core r2.0 have enabled eager execution by default. so, without changing it we just have to change our code

# Launch the graph in a session.
with tf.compat.v1.Session() as ses:

 # Build a graph.
 a = tf.constant(5.0)
 b = tf.constant(6.0)
 c = a * b

 # Evaluate the tensor `c`.
 print(ses.run(c))

This gives the output without any errors And one more thing to make eager execution enable in case then remember it has to be called in the startup of the algorithm For more please go through documentation If any issues please feel free to ask. By the way i am just a beginner in tensorflow and keras. Thank You !

Krishna Rohith
  • 74
  • 1
  • 1
  • 11