【发布时间】:2016-06-23 00:51:19
【问题描述】:
如何编写分段 TensorFlow 函数,即其中包含 if 语句的函数?
当前代码
import tensorflow as tf
my_fn = lambda x : x ** 2 if x > 0 else x + 5
with tf.Session() as sess:
x = tf.Variable(tf.random_normal([100, 1]))
output = tf.map_fn(my_fn, x)
错误:
TypeError:不允许将tf.Tensor 用作Python bool。使用if t is not None:而不是if t:来测试是否定义了张量,并使用逻辑TensorFlow ops来测试张量的值。
【问题讨论】:
标签: python tensorflow