class
ReLU
extends
ModuleReLU(inplace: bool = False)Rectified Linear Unit activation function.
Applies element-wise:
The simplest non-linear activation — sets all negative values to zero. Commonly used in hidden layers of deep networks because it avoids the vanishing-gradient problem that affects sigmoid and tanh for large inputs, and is inexpensive to compute.
Parameters
inplacebool= FalseIf
True, the operation modifies the input tensor in-place,
saving memory allocation. Default: False.Notes
- Input: — any shape.
- Output: — same shape as input.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.ReLU()
>>> x = lucid.tensor([-1.0, 0.0, 1.0, 2.0])
>>> m(x)
tensor([0., 0., 1., 2.])
>>> # Applied to a batch of feature vectors; negatives zeroed, shape preserved
>>> m = nn.ReLU(inplace=True)
>>> x = lucid.randn(4, 64)
>>> out = m(x)
>>> out.shape
(4, 64)Methods (3)
dunder
__init__
→None__init__(inplace: bool = False)Initialise the ReLU 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.