lundi 1 août 2016

How to pass parmeters to functions inside tf.cond in Tensorflow?

I have following simple placeholders:

x = tf.placeholder(tf.float32, shape=[1])
y = tf.placeholder(tf.float32, shape=[1])
z = tf.placeholder(tf.float32, shape=[1])

There are two functions f1 and f2 defined as:

def fn1(a, b): 
    return tf.mul(a, b)
def fn2(a, b): 
    return tf.add(a, b)

Now I want to calculate result based on pred condition:

pred = tf.placeholder(tf.bool, shape=[1])
result = tf.cond(pred, f1(x,y), f2(y,z))

But it gives me an error saying fn1 and fn2 must be callable.

How can I write fn1 and fn2 so that they can receive parameters at runtime? I want to call the following:

sess.run(result, feed_dict={x:1,y:2,z:3,pred:True})

Aucun commentaire:

Enregistrer un commentaire