我的图表中需要一个条件控制流程.如果pred
是True
,则图形应该调用更新变量的op然后返回它,否则它将返回变量不变.简化版本是:
pred = tf.constant(True)
x = tf.Variable([1])
assign_x_2 = tf.assign(x, [2])
def update_x_2():
with tf.control_dependencies([assign_x_2]):
return tf.identity(x)
y = tf.cond(pred, update_x_2, lambda: tf.identity(x))
with tf.Session() as session:
session.run(tf.initialize_all_variables())
print(y.eval())
Run Code Online (Sandbox Code Playgroud)
不过,我觉得,无论pred=True
并pred=False
导致相同的结果y=[2]
,这意味着分配运算时也被称为update_x_2
没有被选中tf.cond
.怎么解释这个?以及如何解决这个问题?
我正在尝试使用tf.data.Dataset交错两个数据集,但遇到了问题.给出这个简单的例子:
ds0 = tf.data.Dataset()
ds0 = ds0.range(0, 10, 2)
ds1 = tf.data.Dataset()
ds1 = ds1.range(1, 10, 2)
dataset = ...
iter = dataset.make_one_shot_iterator()
val = iter.get_next()
Run Code Online (Sandbox Code Playgroud)
什么是...
产生类似的输出0, 1, 2, 3...9
?
似乎dataset.interleave()似乎是相关的,但我无法以不产生错误的方式表达语句.
tensorflow ×2