尝试运行以下基本示例来运行条件计算时,我收到以下错误消息:
'x' was passed float incompatible with expected float_ref
什么是 tensorflow float_ref 以及如何修改代码?
import tensorflow as tf
from tensorflow.python.ops.control_flow_ops import cond
a = tf.Variable(tf.constant(0.),name="a")
b = tf.Variable(tf.constant(0.),name="b")
x = tf.Variable(tf.constant(0.),name="x")
def add():
x.assign( a + b)
return x
def last():
return x
calculate= cond(x==0.,add,last)
with tf.Session() as s:
val = s.run([calculate], {a: 1., b: 2., x: 0.})
print(val) # 3
val=s.run([calculate],{a:4.,b:5.,x:val})
print(val) # 3
最佳答案
仅供引用。 我遇到了类似的错误,我的错误是:
node GradientDescent/update_input/ApplyGradientDescent was passed float from _arg_input_0_1:0 incompatible with expected float_ref.
发生这种情况是因为在我的节点树中某处有一个 tf.Variable
而不是 t.fplaceholder
。用占位符替换变量后,它起作用了。
关于python - 什么是 tensorflow float ref?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34265768/