您必须使用dtype float和shape [2,2]输入占位符张量“占位符”的值

时间:2018-10-19 09:17:57

标签: python tensorflow

我遇到You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [2,2]错误。我已经喂过占位符aa

import numpy as np
import tensorflow as tf

aa = tf.placeholder(dtype=tf.float32, shape=(2, 2))
bb = tf.Variable(aa)
init = tf.global_variables_initializer()
with tf.Session() as sess:
  sess.run(init)
  print(sess.run(bb,feed_dict={aa:np.random.rand(2,2)}))

1 个答案:

答案 0 :(得分:1)

问题出在sess.run(init)中;您需要aa的值才能初始化bb。不过,aa以后不需要检索bb,因为已经为其分配了值。

import numpy as np
import tensorflow as tf

aa = tf.placeholder(dtype=tf.float32, shape=(2, 2))
bb = tf.Variable(aa)
init = tf.global_variables_initializer()
with tf.Session() as sess:
  sess.run(init, feed_dict={aa: np.random.rand(2, 2)})
  print(sess.run(bb))