tf.cond中如何带参数

适用lambda进行传参:

x = tf.placeholder(tf.float32)

y = tf.placeholder(tf.float32)

z = tf.placeholder(tf.float32)

def fn1(a, b):

  return tf.mul(a, b)

def fn2(a, b):

  return tf.add(a, b)

pred = tf.placeholder(tf.bool)

result = tf.cond(pred, lambda: fn1(x, y), lambda: fn2(y, z))

你可能感兴趣的:(tf.cond中如何带参数)