I want update_op
to run before I run summary
. Sometimes I just create a tf.summary
, and everything works just fine, but sometimes I want to do more fancy stuff, but still have the same control dependency.
Code that doesn't work:
with tf.control_dependencies([update_op]):
if condition:
tf.summary.scalar('summary', summary)
else:
summary = summary
Bad hack that works
with tf.control_dependencies([update_op]):
if condition:
tf.summary.scalar('summary', summary)
else:
summary += 0
The problem is that summary=summary
doesn't create a new node, so the control dependency is ignored.
I am sure that there is a way better way of going about this, any suggestions? :-)
I don't think there exists a more elegant solution to this, because this the designed behavior.
tf.control_dependencies
is a shortcut oftf.Graph.control_dependencies
call using a default graph, and here's the quote from its documentation:So just use
tf.identity(summary)
, as suggested in the comments.