Tensorflow(十七) —— 网络的输出方式
1. 主要方式
1、y∈R
2、y∈[0,1]
3、y∈[0,1] Σy = 1
4、y∈[-1,1]
2. y∈[0,1] sigmod
# ************ y∈[0,1] sigmod
a = tf.linspace(-6.,6.,10)
b = tf.sigmoid(a)
print("a:",a.numpy(),"\n","b:",b.numpy())
x = tf.random.normal([1,28,28])*5
print("x:",tf.reduce_min(x).numpy(),tf.reduce_max(x).numpy())
y = tf.nn.sigmoid(x)
print("y:",tf.reduce_min(y).numpy(),tf.reduce_max(y).numpy())
3. y∈[0,1] Σy = 1 softmax
"""
没有加激活函数之前的输出称为logits
"""
"""
logits => probablities (by softmax)
"""
a = tf.linspace(-2.,2.,10)
b = tf.nn.softmax(a)
print("b:",b.numpy())
logits = tf.random.uniform([1,10],minval=-2.,maxval=2.)
prob = tf.nn.softmax(logits)
print("prob:",prob.numpy())
print("sum:",tf.reduce_sum(prob).numpy())
4. y∈[-1,1] tanh
# ****************** y∈[-1,1] tanh
logits = tf.linspace(-10.,10.,20)
out = tf.nn.tanh(logits)
print(out.numpy())
本文为参考龙龙老师的“深度学习与TensorFlow 2入门实战“课程书写的学习笔记
by CyrusMay 2022 04 17