gpt4 book ai didi

python - 什么是 tensorflow float ref?

转载 作者:太空狗 更新时间:2023-10-30 01:06:57 29 4
gpt4 key购买 nike

尝试运行以下基本示例来运行条件计算时,我收到以下错误消息:

'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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com