Feeds

A feed mechanism is provided to patch a tensor into a graph node. It temporarily replaces the output of an operation with a tensor value. The feed is only used for the run call to which it is passed using the feed_dict parameter. The most common use case involves designating specific operations to be feed operations by using tf.placeholder() to create them.

The following example shows how to feed data to build a random 2×3 matrix:

import tensorflow as tf 
import numpy as np

a = 3
b = 2
x = tf.placeholder(tf.float32,shape=(a,b))
y = tf.add(x,x)
data = np.random.rand(a,b)
sess = tf.Session()
print sess.run(y,feed_dict={x:data})

The output is as follows:

>>> 
[[ 1.78602004 1.64606333]
[ 1.03966308 0.99269408]
[ 0.98822606 1.50157797]]
>>>
..................Content has been hidden....................

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