- f1-f2=leak 這樣可以避免使用if判斷語句
"""Activations for TensorFlow.
Parag K. Mital, Jan 2016."""
import tensorflow as tf
def lrelu(x, leak=0.2, name="lrelu"):
"""Leaky rectifier.
Parameters
----------
x : Tensor
The tensor to apply the nonlinearity to.
leak : float, optional
Leakage parameter.
name : str, optional
Variable scope to use.
Returns
-------
x : Tensor
Output of the nonlinearity.
"""
with tf.variable_scope(name):
f1 = 0.5 * (1 + leak) # 0.6
f2 = 0.5 * (1 - leak) # 0.4
return f1 * x + f2 * abs(x)