Fetches

To fetch the outputs of operations, execute the graph by calling the run() function on the Session object and pass in the tensors to be retrieved. Except for fetching the single tensor node, you can also fetch multiple tensors. In the following example, the sum_ and multiply_ tensors are fetched together, using the run() call:

import tensorflow as tf 

constant_A = tf.constant([100.0])
constant_B = tf.constant([300.0])
constant_C = tf.constant([3.0])

sum_ = tf.add(constant_A,constant_B)
mul_ = tf.multiply(constant_A,constant_C)

with tf.Session() as sess:
result = sess.run([sum_,mul_])
print(result)

The output is as follows:

>>> 
[array([ 400.],dtype=float32),array([ 300.],dtype=float32)]

All the ops needed to produce the values of the requested tensors are run once (not once per requested tensor).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset