评价此页

PReLU#

class torch.nn.PReLU(num_parameters=1, init=0.25, device=None, dtype=None)[source]#

应用逐元素的 PReLU 函数。

PReLU(x)=max(0,x)+amin(0,x)\text{PReLU}(x) = \max(0,x) + a * \min(0,x)

PReLU(x)={x, if x0ax, otherwise \text{PReLU}(x) = \begin{cases} x, & \text{ if } x \ge 0 \\ ax, & \text{ otherwise } \end{cases}

其中 aa 是一个可学习的参数。当不带参数调用时,nn.PReLU() 对所有输入通道使用一个 aa。如果使用 nn.PReLU(nChannels) 调用,则为每个输入通道使用一个单独的 aa

注意

学习 aa 时,不应使用权重衰减以获得良好性能。

注意

通道维度是输入的第二个维度。当输入维度小于 2 时,则没有通道维度,通道数为 1。

参数
  • num_parameters (int) – 要学习的 aa 的数量。尽管它接受一个整数作为输入,但只有两个值是合法的:1,或者输入通道的数量。默认值:1

  • init (float) – aa 的初始值。默认值:0.25

形状
  • 输入: ()( *),其中 * 表示任何数量的附加维度。

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

变量

weight (Tensor) – 形状为 (num_parameters) 的可学习权重。

../_images/PReLU.png

示例

>>> m = nn.PReLU()
>>> input = torch.randn(2)
>>> output = m(input)