刚开始学习的时候碰到了 placeholder()
在tensorflow中的placeholder 定义如下
`tf.placeholder(dtype, shape=None, name=None)`
简单理解下就是占位符的意思,先放在这里,然后在需要的时候给网络传输数据
直接传递给run()会报错哦,必须通过 feed_dict方法 传递给 Session.run(), Tensor.eval(),或者Operation.run()
举个栗子
x = tf.placeholder(float, shape=(1024, 1024))
y = tf.matmul(x, x)
with tf.Session() as sess:
print sess.run(y) # ERROR: will fail because x was not fed.也就是会报错咯,没有通过feed_dict传递
rand_array = np.random.rand(1024, 1024)
print sess.run(y, feed_dict={x: rand_array}) # Will succeed.这个才是对的咯