mindspore.nn.LeakyReLU
- class mindspore.nn.LeakyReLU(alpha=0.2)[源代码]
- 逐元素计算Leaky ReLU激活函数。 - 该激活函数定义如下: \[\text{leaky_relu}(x) = \begin{cases}x, &\text{if } x \geq 0; \cr {\alpha} * x, &\text{otherwise.}\end{cases}\]- 其中,\(\alpha\) 表示 alpha 参数。 - 更多细节详见 Rectifier Nonlinearities Improve Neural Network Acoustic Models 。 - LeakyReLU函数图:   - 参数:
- alpha (Union[int, float]) - x 小于0时激活函数的斜率,默认值: - 0.2。
 
- 输入:
- x (Tensor) - 计算LeakyReLU的任意维度的Tensor。 
 
- 输出:
- Tensor,数据类型和shape与 x 相同。 
- 异常:
- TypeError - alpha 不是浮点数或整数。 
 
- 支持平台:
- Ascend- GPU- CPU
 - 样例: - >>> import mindspore >>> from mindspore import Tensor, nn >>> import numpy as np >>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32) >>> leaky_relu = nn.LeakyReLU() >>> output = leaky_relu(x) >>> print(output) [[-0.2 4. -1.6] [ 2. -1. 9. ]]