PReLU

class paddle.nn. PReLU ( num_parameters=1, init=0.25, weight_attr=None, name=None ) [source]

PReLU Activation.

\[PReLU(x) = max(0, x) + weight * min(0, x)\]
Parameters
  • num_parameters (int, optional) – Number of weight to learn. The supported values are: 1 - a single parameter alpha is used for all input channels; Number of channels - a seperate alpha is used for each input channel. Default is 1.

  • init (float, optional) – Init value of learnable weight. Default is 0.25.

  • weight_attr (ParamAttr, optional) – The parameter attribute for the learnable weight. Default is None. For more information, please refer to api_paddle_ParamAttr.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Shape:
  • input: Tensor with any shape. Default dtype is float32.

  • output: Tensor with the same shape as input.

Examples

import paddle
import numpy as np

paddle.set_default_dtype("float64")

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]]]], 'float64')
x = paddle.to_tensor(data)
m = paddle.nn.PReLU(1, 0.25)
out = m(x)
# [[[[-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.  ]]]]
forward ( x )

Defines the computation performed at every call. Should be overridden by all subclasses.

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )

Extra representation of this layer, you can have custom implementation of your own layer.