class oneflow.nn.PReLU(num_parameters: int = 1, init: float = 0.25, device=None, dtype=None)

Applies the element-wise function:

\[PReLU(x) = \max(0,x) + a * \min(0,x)\]

Here \(a\) is a learnable parameter. When called without arguments, nn.PReLU() uses a single parameter \(a\) across all input channels. If called with nn.PReLU(nChannels), a separate \(a\) is used for each input channel.


weight decay should not be used when learning \(a\) for good performance.


Channel dim is the 2nd dim of input. When input has dims < 2, then there is no channel dim and the number of channels = 1.

  • num_parameters (int) – number of \(a\) to learn. Although it takes an int as input, there is only two values are legitimate: 1, or the number of channels at input. Default: 1

  • init (float) – the initial value of \(a\). Default: 0.25

  • Input: \((N, *)\) where * means, any number of additional dimensions

  • Output: \((N, *)\), same shape as the input

  • weight (Tensor): the learnable weights of shape (num_parameters).

>>> import numpy as np
>>> import oneflow as flow

>>> m = flow.nn.PReLU()
>>> input = flow.tensor(np.asarray([[[[1, -2], [3, 4]]]]), dtype=flow.float32)
>>> print(m(input).numpy())
[[[[ 1.  -0.5]
   [ 3.   4. ]]]]