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 input tensor itself receives the result. 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.])
>>> # In place: the input itself holds the result
>>> x = lucid.tensor([-1.0, 2.0])
>>> nn.ReLU(inplace=True)(x) is x, x
(True, tensor([0., 2.]))