tf.assert_positive()如果x中有负数就抛出异常,跟tf.assert_non_negative() 作用一样
参数:
tf.assert_positive(
x,
data=None,
summarize=None,
message=None,
name=None
)
使用案例:
import tensorflow as tf
x = [1, 1]
sess = tf.Session()
with tf.control_dependencies([tf.assert_positive(x)]):
output = tf.reduce_sum(x)
print(sess.run(output))