Python Tensorflow:在丢失操作中使用tf.cond的问题

Python Tensorflow:在丢失操作中使用tf.cond的问题,python,machine-learning,tensorflow,control-flow,Python,Machine Learning,Tensorflow,Control Flow,我试图在培训阶段使用加权损失,但在验证阶段不使用加权损失。我的想法是使用tf.cond和一个占位符is\u training,我将用feed\u dict输入它(对或错) 当我单独对错误进行测试时,它会工作,但只要我使用tf.cond我就会得到: tensorflow.python.framework.errors_impl.InvalidArgumentError: The tensor returned for train_op:0 was not valid. loss操作在培训期间使用

我试图在培训阶段使用加权损失,但在验证阶段不使用加权损失。我的想法是使用
tf.cond
和一个占位符
is\u training
,我将用
feed\u dict
输入它(对或错)

当我单独对错误进行测试时,它会工作,但只要我使用
tf.cond
我就会得到:

tensorflow.python.framework.errors_impl.InvalidArgumentError: The tensor returned for train_op:0 was not valid.
loss
操作在培训期间使用如下(在验证期间,它仅由
sess.run()
调用): 正则化损失被添加到
tf.集合中
,所有损失都被添加。然后:

gradients = optimizer.compute_gradients(total_loss, variables_to_train)
grad_updates = optimizer.apply_gradients(gradients,global_step=global_step)
如何使用tensorflow控制流


编辑:
tensorflow gpu 1.0.1

我在权重张量上使用了
tf.cond
,效果很好。然而,我仍然感兴趣的是,为什么上面的方法不起作用,我在权重张量上使用了
tf.cond
,这是有效的。然而,我仍然对上述方法不起作用的原因感兴趣
gradients = optimizer.compute_gradients(total_loss, variables_to_train)
grad_updates = optimizer.apply_gradients(gradients,global_step=global_step)