I would like to have an example illustrating the use of the function tf.control_dependencies
. For example, I want to create two tensors X
and Y
and if they are equal do or print something.
import tensorflow as tf session = tf.Session() X = tf.constant(5) Y = tf.constant(50) with tf.control_dependencies([tf.assert_equal(X, Y)]): print('X and Y are equal!')
In the code above, X
is clearly not equal to Y
. What is tf.control_dependencies
doing in this case?
control_dependencies
is not a conditional. It is a mechanism to add dependencies to whatever ops you create in the with
block. More specifically, what you specify in the argument to control_dependencies
is ensured to be evaluated before anything you define in the with
block.
In your example, you don't add any (TensorFlow) operations in the with
block, so the block does nothing.
This answer has an example of how to use control_dependencies
, where it is used to make sure the assignments happen before the batchnorm operations are evaluated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With