Skip to content

Instantly share code, notes, and snippets.

@vanangamudi
Created May 23, 2017 13:19
Show Gist options
  • Save vanangamudi/c64b5d45aef382af1b3be77c3c9ccb7d to your computer and use it in GitHub Desktop.
Save vanangamudi/c64b5d45aef382af1b3be77c3c9ccb7d to your computer and use it in GitHub Desktop.
Tensorflow conditional statement
import tensorflow as tf
training = tf.placeholder(dtype=tf.bool, name='is_training')
a = tf.placeholder(dtype=tf.float32, name='a')
b = tf.placeholder(dtype=tf.float32, name='b')
c = tf.cond(training, lambda : a+b, lambda : a*b)
sess = tf.Session()
op = sess.run(c, feed_dict = {
a : 1., b : 2., training : False
})
print(op) # 2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment