RReLU
ModuleRReLU(lower: float = 1.0 / 8.0, upper: float = 1.0 / 3.0, inplace: bool = False)Randomized Leaky ReLU activation function.
During training, the negative slope for each element is drawn independently and uniformly from :
During evaluation, the slope is fixed at the deterministic midpoint .
The stochastic negative slope acts as a form of noise-based regularisation, similar in spirit to Dropout, and was found to improve generalisation in image classification tasks.
Parameters
lowerfloat= 1.0 / 8.01/8.upperfloat= 1.0 / 3.01/3.inplacebool= FalseTrue, modifies the input tensor in-place. Default: False.Notes
- Input: — any shape.
- Output: — same shape as input.
Call m.train() / m.eval() to switch between stochastic and
deterministic modes respectively. The module inherits training-mode
tracking from lucid.nn.Module.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.RReLU(lower=0.1, upper=0.3)
>>> x = lucid.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
>>> out_train = m(x) # slope sampled from U(0.1, 0.3)
>>> m.eval()
>>> out_eval = m(x) # slope fixed at 0.2
>>> out_eval.shape
(5,)Methods (3)
__init__
→None__init__(lower: float = 1.0 / 8.0, upper: float = 1.0 / 3.0, inplace: bool = False)Initialise the RReLU module. See the class docstring for parameter semantics.
forward
→Tensorforward(x: Tensor)Apply the activation function element-wise.
Parameters
inputTensorReturns
TensorOutput tensor of the same shape as input.
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.