prelu

paddle.nn.functional. prelu ( x: Tensor, weight: Tensor, data_format: DataLayout2D = 'NCHW', name: str | None = None ) → Tensor [source]

prelu activation. The calculation formula is follows:

\[prelu(x) = max(0, x) + weight * min(0, x)\]

x and weight is input Tensor.

Parameters
  • x (Tensor) – The input Tensor with data type float32, float64. Alias: input.

  • weight (Tensor) – The learnable parameter with data type same as x. The weight shape is [], [1] or [in], where in is the input channel of x.

  • name (str|None, optional) – For details, please refer to api_guide_Name. Generally, no setting is required. Default: None.

  • data_format (str, optional) – Data format that specifies the layout of input. It may be “NC”, “NCL”, “NCHW”, “NCDHW”, “NLC”, “NHWC” or “NDHWC”. Default: “NCHW”.

Returns

A Tensor with the same data type and shape as x .

Examples

>>> import paddle
>>> import paddle.nn.functional as F

>>> data = paddle.to_tensor(
...     [
...         [
...             [
...                 [-2.0, 3.0, -4.0, 5.0],
...                 [3.0, -4.0, 5.0, -6.0],
...                 [-7.0, -8.0, 8.0, 9.0],
...             ],
...             [
...                 [1.0, -2.0, -3.0, 4.0],
...                 [-5.0, 6.0, 7.0, -8.0],
...                 [6.0, 7.0, 8.0, 9.0],
...             ],
...         ]
...     ],
...     dtype='float32',
... )

>>> w = paddle.to_tensor([0.25], dtype='float32')
>>> out = F.prelu(data, w)
>>> print(out)
Tensor(shape=[1, 2, 3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[[-0.50000000,  3.        , -1.        ,  5.        ],
   [ 3.        , -1.        ,  5.        , -1.50000000],
   [-1.75000000, -2.        ,  8.        ,  9.        ]],
  [[ 1.        , -0.50000000, -0.75000000,  4.        ],
   [-1.25000000,  6.        ,  7.        , -2.        ],
   [ 6.        ,  7.        ,  8.        ,  9.        ]]]])