Apply ordinary ReLU between layers using the default arguments.
Standard neural-network activation
Keras · Class
keras.layers.ReLU is an element-wise rectified-linear activation layer. Its parameters support an upper cap, a nonzero below-threshold slope, and a nonzero threshold.
ReLU is a callable Keras layer that transforms each input element using a threshold, an optional negative-side slope, and an optional upper cap. With defaults it produces the usual element-wise maximum of the input and zero, while configured values can make it leaky, thresholded, or clipped.
keras.layers.ReLU(max_value=None, negative_slope=0.0, threshold=0.0, **kwargs)| Name | Type | Description |
|---|---|---|
max_value | float or None | Upper bound for the activation; None leaves it unlimited. Must be at least 0. |
negative_slope | float | Coefficient used by the below-threshold branch. Must be at least 0. |
threshold | float | Threshold used by the thresholded activation. Must be at least 0. |
**kwargs | keyword arguments | Additional base Layer keyword arguments, such as name and dtype. |
A tensor with the ReLU transformation applied element-wise; the output has the same shape as the input.
import keras
import numpy as np
relu = keras.layers.ReLU(
max_value=10.0,
negative_slope=0.5,
threshold=0.0,
)
print(relu(np.array([-10.0, -5.0, 0.0, 5.0, 10.0])).numpy())Creates a capped, leaky, thresholded ReLU and applies it element-wise to a NumPy array.
Standard neural-network activation
Leaky activation
Bounded activation
Thresholded activation
ReLU is an element-wise activation layer. With default arguments, it computes the maximum of each input value and zero.
Follow-up: How can it represent a leaky or capped variant? Set negative_slope above zero for the below-threshold branch, and set max_value to impose an upper limit.
max_value limits the largest activation, while negative_slope controls the coefficient applied below the threshold. A max_value of None means the activation is not capped.
Follow-up: What constraints apply to these arguments? The documentation specifies nonnegative values for max_value and negative_slope.
The layer accepts arbitrary input shapes and returns outputs with the same shape as the input. It can therefore be inserted into a model without changing tensor dimensions.
Follow-up: How can it be used as a model's first layer? Supply input_shape as a keyword argument, excluding the batch axis.
keras.layers.Activationkeras.activations.relukeras.activations.relu6