tensorflow Using if condition inside the TensorFlow graph with tf.cond Basic example


Example

x = tf.constant(1.)
bool = tf.constant(True)

res = tf.cond(bool, lambda: tf.add(x, 1.), lambda: tf.add(x, 10.))
# sess.run(res) will give you 2.