Module: tf.keras.activations
activations類保存了各種激活函數
activations類的方法:
elu(): 指數線性單位;
exponential(): 指數激活函數;
get()
hard_sigmoid(): Hard sigmoid 激活函數;
linear(): 線性激活函數;
relu(): relu激活函數;
selu(): SELU激活函數;
serialize()
sigmoid(): Sigmoid 激活函數;
softmax(): softmax 激活函數;
softplus(): Softplus 激活函數。
softsign():
tanh():
1 tf.keras.activations.deserialize( 2 name, 3 custom_objects=None 4 )
1 tf.keras.activations.elu( 2 x, 3 alpha=1.0 4 ) 5 參數: 6 x: Input tensor. 7 alpha: 一個標量,負截面的斜率.
備注:
if x>0:
x
else:
alpha*(exp(x)-1)
1 tf.keras.activations.exponential(x)
1 tf.keras.activations.get(identifier)
1 tf.keras.activations.hard_sigmoid(x)
備注:
if x<-2.5:
0
elif x>2.5:
1
else:
-0.2*x + 0.5
1 tf.keras.activations.linear(x)
1 tf.keras.activations.relu( 2 x, 3 alpha=0.0, 4 max_value=None, 5 threshold=0 6 ) 7 參數: 8 x: 變量、張量; 9 alpha: 一個標量,負截面的坡度(默認值為0); 10 max_value: 浮點值,飽和閾值; 11 threshold:閾值激活的閾值,浮點值。
1 tf.keras.activations.selu(x)
備注:調用方法
n_classes = 10 #10_class problem
model = models.Sequential()
model.add(Dense(64, kernel_initializer='lecun_normal', activation='selu',
input_shape=(28, 28, 1))))
model.add(Dense(32, kernel_initializer='lecun_normal', activation='selu'))
model.add(Dense(16, kernel_initializer='lecun_normal', activation='selu'))
model.add(Dense(n_classes, activation='softmax'))
1 tf.keras.activations.serialize(activation)
1 tf.keras.activations.sigmoid(x)
備注:
(1.0 / (1.0 + exp(-x)))
1 tf.keras.activations.softmax( 2 x, 3 axis=-1 4 ) 5 參數: 6 x:輸入張量; 7 axis: 應用SoftMax規范化的軸,整數。

1 tf.keras.activations.softplus(x)
備注:
log(exp(x) + 1)
1 tf.keras.activations.softsign(x)
備注:
x / (abs(x) + 1)
1 tf.keras.activations.tanh(x)
備注:
tanh(x) = sinh(x)/cosh(x) = ((exp(x) - exp(-x))/(exp(x) + exp(-x)))