Skip to content Skip to sidebar Skip to footer

How To Feed A Placeholder?

I am trying to implement a simple feed forward network. However, I can't figure out how to feed a Placeholder. This example: import tensorflow as tf num_input = 2 num_hidden = 3

Solution 1:

To feed a placeholder, you use the feed_dict argument to Session.run() (or Tensor.eval()). Let's say you have the following graph, with a placeholder:

x = tf.placeholder(tf.float32, shape=[2, 2])
y = tf.constant([[1.0, 1.0], [0.0, 1.0]])
z = tf.matmul(x, y)

If you want to evaluate z, you must feed a value for x. You can do this as follows:

sess = tf.Session()
print sess.run(z, feed_dict={x: [[3.0, 4.0], [5.0, 6.0]]})

For more information, see the documentation on feeding.


Post a Comment for "How To Feed A Placeholder?"