import tensorflow as tf
All operations are added to default graph if nothing is specified
tf.reset_default_graph()
a = tf.constant(2)
b = tf.constant(5)
c = a + b
g_default = tf.get_default_graph()
g_default.get_operations()
Building a new graph
NOTE: Do not use the tensors from another graph
g = tf.Graph()
g.get_operations()
with g.as_default():
#x = a #cant use a here
e = tf.constant(2)
f = tf.constant(5)
h = e*f
print(g.get_operations())
#g is not default here
List the operations under two graphs
g_default.get_operations()
g.get_operations()
Running default graph
with tf.Session() as sess:
print(sess.run(c))
#print(sess.run(h)) #breaks
Running the new graph
with g.as_default():
with tf.Session() as sess:
print(sess.run(h))