Understanding Session and Graph
Created at 2017-07-14 Updated at 2017-07-14
The first time when I learned TensorFlow, I was confused by Session and Graph. After Googling for a while, I knew that
- Graph defines operations in your applicaion, it defines computation and has nothing to do with data.
- When running the Graph by session, dimensions and type of values will be checked and errors will be raised when there are some bugs in the Graph.
- To run the Graph, one must feed the data.
And Session, in my view is Conversation— you need a talk with the Graph and tell the Graph what you want, so in order to expel the Graph to conduct computation, you should plugin the fuel— feed_dict and run the Graph to get get the value you want defined in the Graph— to call
sess.run([values you want], feed_dict).
And if you use
with — the conext manager in your session, every time you should initialize variables in the Graph. Multiple sessions and multiple graphs can be defined and you can use sessions to call different graphs.
Everytime when a session is created, one must set a graph defined before or use the defult graph.
Since the graph of
init_graph_2 is defined in
sess_1 can’t run
init_graph_2. And the same as values defined in the Graphs!
And you can also use
InteractiveSession to run the Graph.
OK, that all my understadings. Session is a Conversation to communicate with the Graph, Graph is a computation paradigm!