【发布时间】:2020-10-20 03:47:33
【问题描述】:
当我运行以下代码 (tf v1.12.0) 时,我得到 6.0 (x->mul->ident)、7.0 (x->mul->add->ident 或 9.0 (x->add ->mul->ident)。
有人可以解释为什么操作的执行顺序不受 tf.control_dependencies 控制吗?我认为至少 add_op 会在控制上下文中的任何内容被考虑之前执行。
tf.reset_default_graph()
x=tf.Variable(2.0)
add_op = tf.assign_add(x, 1)
mul_op = tf.assign(x, 3*x)
with tf.control_dependencies([add_op]):
out_op = tf.identity(mul_op)
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)
print(sess.run([out_op]))
谢谢!
【问题讨论】:
标签: tensorflow graph dependencies execution order-of-execution