Reputation: 8135
I tried to create graphs from different sessions by :
sess1 = tf.Session()
print(sess1)
print(sess1.graph)
sess2 = tf.Session()
print(sess2)
print(sess2.graph)
sess3 = tf.Session()
print(sess3)
print(sess3.graph)
and the result is
<tensorflow.python.client.session.Session object at 0x14305b2b0>
<tensorflow.python.framework.ops.Graph object at 0x14305ba20>
<tensorflow.python.client.session.Session object at 0x14305b9b0>
<tensorflow.python.framework.ops.Graph object at 0x14305ba20>
<tensorflow.python.client.session.Session object at 0x14305b908>
<tensorflow.python.framework.ops.Graph object at 0x14305ba20>
I don't understand, since I expected different sessions would have different graphs, but in this case, different sessions shared the same graph object... ?
Is there a way to solve this problem?
Thank you.
Upvotes: 2
Views: 499
Reputation: 1845
According to the documentation:
If no graph argument is specified when constructing the session, the default graph will be launched in the session.
And that's why you get the same graph for different sessions. To solve it, you can simply provide a graph when creating the session:
sess1 = tf.Session(graph=tf.Graph())
print(sess1)
print(sess1.graph)
sess2 = tf.Session(graph=tf.Graph())
print(sess2)
print(sess2.graph)
sess3 = tf.Session(graph=tf.Graph())
print(sess3)
print(sess3.graph)
Which results in:
<tensorflow.python.client.session.Session object at 0x10589c9d0>
<tensorflow.python.framework.ops.Graph object at 0x104729d10>
<tensorflow.python.client.session.Session object at 0x114d0afd0>
<tensorflow.python.framework.ops.Graph object at 0x114cf8c50>
<tensorflow.python.client.session.Session object at 0x114d0ae50>
<tensorflow.python.framework.ops.Graph object at 0x114d0af90>
Upvotes: 2