prelu

paddle.nn.functional. prelu ( x, weight, data_format='NCHW', name=None ) [source]

prelu activation.

\[prelu(x) = max(0, x) + weight * min(0, x)\]
Parameters
  • x (Tensor) – The input Tensor with data type float32, float64.

  • 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, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

  • 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
import numpy as np

data = np.array([[[[-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]]]], 'float32')
x = paddle.to_tensor(data)
w = paddle.to_tensor(np.array([0.25]).astype('float32'))
out = F.prelu(x, w)
# [[[[-0.5 ,  3.  , -1.  ,  5.  ],
#    [ 3.  , -1.  ,  5.  , -1.5 ],
#    [-1.75, -2.  ,  8.  ,  9.  ]],
#   [[ 1.  , -0.5 , -0.75,  4.  ],
#    [-1.25,  6.  ,  7.  , -2.  ],
#    [ 6.  ,  7.  ,  8.  ,  9.  ]]]]