Shortcuts

LeakyReLU

class torch.nn.LeakyReLU(negative_slope=0.01, inplace=False)[源代码]

逐元素应用LeakyReLU函数。

LeakyReLU(x)=max(0,x)+negative_slopemin(0,x)\text{LeakyReLU}(x) = \max(0, x) + \text{negative\_slope} * \min(0, x)

LeakyReLU(x)={x, if x0negative_slope×x, otherwise \text{LeakyReLU}(x) = \begin{cases} x, & \text{ if } x \geq 0 \\ \text{negative\_slope} \times x, & \text{ otherwise } \end{cases}
Parameters
  • negative_slope (float) – 控制负斜率的角度(用于负输入值)。默认值:1e-2

  • inplace (布尔值) – 可以选择就地执行操作。默认值:False

Shape:
  • 输入:()(*) 其中 * 表示任意数量的额外维度

  • 输出: ()(*), 与输入形状相同

../_images/LeakyReLU.png

示例:

>>> m = nn.LeakyReLU(0.1)
>>> input = torch.randn(2)
>>> output = m(input)
优云智算