【发布时间】:2019-03-14 21:59:57
【问题描述】:
如何使用占位符创建变量作为初始值设定项?下图分解为:
InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float
[[node Placeholder_1 (defined at <ipython-input-10-b8d54264dc85>:3) = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
我的代码:
tf.reset_default_graph()
a = tf.placeholder(dtype=tf.float32,shape=())
d = tf.placeholder(dtype=tf.float32,shape=())
b = tf.get_variable(name='b',initializer=d)
c=a+d
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(c, feed_dict={a:5.,d:10.}))
tensorflow 中关于初始化器的文档说:
变量的初始化器(如果已创建)。可以是初始化对象或张量。如果是张量,则必须知道其形状,除非 validate_shape 为 False。
但是,如果我注释掉我创建 b 的行,代码似乎可以运行。我的 fetch 甚至不依赖于 b。
如何创建根据某个占位符进行初始化的变量?
【问题讨论】:
标签: python tensorflow deep-learning