Hello guys I am using Tensorflow 2.0
and in these lines of code:
import tensorflow as tf
hello = tf.constant('Hello World')
sess = tf.compat.v1.Session()
sess.run(hello) <-- Error in this line
RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
Any idea on how to solve it?
g = tf.Graph()
with g.as_default():
# Define operations and tensors in `g`.
hello = tf.constant('hello')
assert hello.graph is g
sess = tf.compat.v1.Session(graph=g)
sess.run(hello)
b'hello'
Tensorflow core r2.0 have enabled eager execution by default. so, without changing it we just have to change our code as like as below by Launch the graph in a session.
> with tf.compat.v1.Session() as sess:
> # Building a graph
> hello = tf.constant("hello")
> print(sess.run(hello))
According to the Tensorflow doc..
A default Graph is always registered, and accessible by calling tf.compat.v1.get_default_graph
For this basic operations not required to declare a tf.Graph() , you can define a graph which has more computations and dataset you can define a graph and invoke into the session.
Please Refer: For More informations https://www.tensorflow.org/api_docs/python/tf/Graph https://github.com/OlafenwaMoses/ImageAI/issues/400
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With