吴裕雄--天生自然TensorFlow2教程:输出方式

sigmoid

 

out' = sigmoid(out) # 把输出值压缩在0-1

import tensorflow as tf
a = tf.linspace(-6., 6, 10)
a
tf.sigmoid(a)
x = tf.random.normal([1, 28, 28]) * 5
tf.reduce_min(x), tf.reduce_max(x)

x = tf.sigmoid(x)
tf.reduce_min(x), tf.reduce_max(x)
a = tf.linspace(-2., 2, 5)
tf.sigmoid(a)  # 输出值的和不为1
softmax
tf.nn.softmax(a)  # 输出值的和为1

logits = tf.random.uniform([1, 10], minval=-2, maxval=2)
logits
prob = tf.nn.softmax(logits, axis=1)
prob
tf.reduce_sum(prob, axis=1)

tf.tanh(a)

猜你喜欢

转载自www.cnblogs.com/tszr/p/12221479.html