How to feed a placeholder?

后端 未结 1 331
旧巷少年郎
旧巷少年郎 2020-12-03 13:58

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          


        
相关标签:
1条回答
  • 2020-12-03 14:27

    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.

    0 讨论(0)
提交回复
热议问题