In [1]:
import tensorflow as tf
In [2]:
n1 = tf.constant(1)
n2 = tf.constant(2)
In [3]:
n3 = n1 + n2
In [4]:
# Using with auto-closes the session
with tf.Session() as sess:
result = sess.run(n3)
print(result)
When you start TF, a default Graph is created, you can create additional graphs easily:
In [5]:
print(tf.get_default_graph())
In [6]:
g = tf.Graph()
In [7]:
print(g)
Setting a graph as the default:
In [8]:
graph_one = tf.get_default_graph()
graph_two = tf.Graph()
In [9]:
graph_one is tf.get_default_graph()
Out[9]:
In [10]:
graph_two is tf.get_default_graph()
Out[10]:
In [11]:
with graph_two.as_default():
print(graph_two is tf.get_default_graph())
In [12]:
graph_two is tf.get_default_graph()
Out[12]: