Keras 3 API 文档 / 层 API / 激活层 / LeakyReLU 层

LeakyReLU 层

[源码]

LeakyReLU

keras.layers.LeakyReLU(negative_slope=0.3, **kwargs)

修正线性单元 (ReLU) 激活层的 leaky (带泄露) 版本。

当单元不激活时,该层允许存在一个小的梯度。

公式

f(x) = alpha * x if x < 0
f(x) = x if x >= 0

示例

leaky_relu_layer = LeakyReLU(negative_slope=0.5)
input = np.array([-10, -5, 0.0, 5, 10])
result = leaky_relu_layer(input)
# result = [-5. , -2.5,  0. ,  5. , 10.]

参数

  • negative_slope:浮点数,必须 >= 0.0。负斜率系数。默认为 0.3
  • **kwargs:基础层关键字参数,例如 namedtype