Reputation: 781
To run a programm with TensorFlow, we must declare a session.
So what is the difference between sess = Session()
and sess = Session(Graph())
?
What is this Graph()
?
Upvotes: 1
Views: 393
Reputation: 46341
Designing a model in TensorFlow assumes these two parts:
Building graph(s), representing the data flow of the computations.
Running a session(s), executing the operations in the graph.
In general case, there can be multiple graphs and multiple sessions. But there is always one default graph and one default session.
In that context sess = Session()
would assume the default session:
If no graph argument is specified when constructing the session, the default graph will be launched in the session.
sess = Session(Graph())
would assume you are using more than one graph.
If you are using more than one graph (created with tf.Graph() in the same process, you will have to use different sessions for each graph, but each graph can be used in multiple sessions. In this case, it is often clearer to pass the graph to be launched explicitly to the session constructor.
Upvotes: 0
Reputation: 11449
When designing a Model in Tensorflow, there are basically 2 steps
A Session object encapsulates the environment in which Operation objects are executed, and Tensor objects are evaluated. For example:
# Launch the graph in a session.
sess = tf.Session()
# Evaluate the tensor `c`.
print(sess.run(c))
When you create a Session you're placing a graph into a specified device and If no graph is specified, the Session constructor tries to build a graph using the default one .
sess = tf.Session()
Else during initializing tf.Session(), you can pass in a graph like tf.Session(graph=my_graph)
with tf.Session(graph=my_graph) as sess:
Upvotes: 3