PRelu

class paddle.fluid.dygraph.PRelu(mode, channel=None, input_shape=None, param_attr=None, dtype='float32')[source]

This interface is used to construct a callable object of the PRelu class. For more details, refer to code examples. It implements three activation methods of the PRelu activation function.

Equation:

\[y = \max(0, x) + \alpha * \min(0, x)\]
Parameters
  • mode (str) – The mode for weight sharing. It supports all, channel and element. all: all elements share same weight channel:elements in a channel share same weight element:each element has a weight

  • channel (int, optional) – The number of channels. This argument is required when mode is “channel”. Default: None.

  • input_shape (list or tuple, optional) – The shape of input. This argument is required when mode is “element”. Default: None.

  • param_attr (ParamAttr, optional) – The parameter attribute for the learnable weight (alpha). Default: None.

  • dtype (str, optional) – Data type, it can be “float32” or “float64”. Default: “float32”.

Attribute:

weight (Parameter): the learnable weights of this layer.

Returns

None

Examples

import paddle.fluid as fluid
from paddle.fluid.dygraph.base import to_variable
import numpy as np

inp_np = np.ones([5, 200, 100, 100]).astype('float32')
with fluid.dygraph.guard():
    inp_np = to_variable(inp_np)
    prelu0 = fluid.PRelu(
       mode='all',
       param_attr=fluid.ParamAttr(initializer=fluid.initializer.Constant(1.0)))
    dy_rlt0 = prelu0(inp_np)
    prelu1 = fluid.PRelu(
       mode='channel',
       channel=200,
       param_attr=fluid.ParamAttr(initializer=fluid.initializer.Constant(1.0)))
    dy_rlt1 = prelu1(inp_np)
    prelu2 = fluid.PRelu(
       mode='element',
       input_shape=inp_np.shape,
       param_attr=fluid.ParamAttr(initializer=fluid.initializer.Constant(1.0)))
    dy_rlt2 = prelu2(inp_np)
forward(input)

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

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments