class
PReLU
extends
ModulePReLU(num_parameters: int = 1, init: float = 0.25, device: DeviceLike = None, dtype: DTypeLike = None)Parametric Rectified Linear Unit activation function.
Applies element-wise:
Unlike LeakyReLU, the slope is a learnable parameter
updated during back-propagation. A single shared slope can be used for
all channels (num_parameters=1) or each channel can have its own
slope (num_parameters=num_channels).
Parameters
num_parametersint= 1Number of learnable slopes. Use
1 for a single shared slope or
set to the number of input channels for per-channel slopes.
Default: 1.initfloat= 0.25Initial value for all slope parameters. Default:
0.25.deviceDeviceLike= NoneDevice on which the parameter tensor is allocated. Default:
None
(uses the default device).dtypeDTypeLike= NoneData type of the parameter tensor. Default:
None (uses the
default floating-point type).Attributes
weightParameter of shape ``(num_parameters,)``Learnable negative slopes . Updated by the optimiser
during training.
Notes
- Input: — any shape.
- Output: — same shape as input.
When num_parameters > 1, the input is expected to have the channel
dimension second (i.e. shape ), and num_parameters
must equal .
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.PReLU(num_parameters=1, init=0.25)
>>> x = lucid.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
>>> m(x)
tensor([-0.5, -0.25, 0. , 1. , 2. ])
>>> # Per-channel slopes for a feature map with 64 channels
>>> m = nn.PReLU(num_parameters=64)
>>> x = lucid.randn(8, 64, 16, 16)
>>> out = m(x)
>>> out.shape
(8, 64, 16, 16)Methods (3)
dunder
__init__
→None__init__(num_parameters: int = 1, init: float = 0.25, device: DeviceLike = None, dtype: DTypeLike = None)Initialise the PReLU module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Apply the activation function element-wise.
Parameters
inputTensorInput tensor of arbitrary shape.
Returns
TensorOutput tensor of the same shape as input.
fn
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.