What does the sentence below quoted from getting started with tensorflow mean?
A session encapsulates the control and state of the TensorFlow runtime.
I know encapsulation in object oriented programming, and also have played with session a bit with success. Still I do not get this sentence very well. Can someone rephrase it in simple words?
A session is an environment of a software system that describes how the lines of code should run. In TensorFlow, a session sets up how the hardware devices (such as CPU and GPU) talk to each other. That way, you can design your machine-learning algorithm without worrying about micromanaging the hardware it runs on.
Tensorflow 2 does not require session.
Syntax of sess. It will run operations and evaluate tensors in fetches. We must notice its return value. If fetches is a tensor, it will return a single value. If fetches is a list, it will return a list.
This encapsulation has nothing to do with OOP encapsulation. A slightly better (in terms of understanding for a new-comer) definition is in session documentation.
A Session object encapsulates the environment in which Operation objects are executed, and Tensor objects are evaluated.
Which means that none the operators and variables defined in the graph-definition part are being executed. For example nothing is being executed/calculated here
a = tf.Variable(tf.random_normal([3, 3], stddev=1.)
b = tf.Variable(tf.random_normal([3, 3], stddev=1.)
c = a + b
You will not get the values of a tensors a/b/c
now. There values will be evaluated only inside of the Session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With