Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

layers.ReLU

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.

How it works

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.

Syntax

keras.layers.ReLU(max_value=None, negative_slope=0.0, threshold=0.0, **kwargs)

Parameters

NameTypeDescription
max_valuefloat or NoneUpper bound for the activation; None leaves it unlimited. Must be at least 0.
negative_slopefloatCoefficient used by the below-threshold branch. Must be at least 0.
thresholdfloatThreshold used by the thresholded activation. Must be at least 0.
**kwargskeyword argumentsAdditional base Layer keyword arguments, such as name and dtype.

Returns

A tensor with the ReLU transformation applied element-wise; the output has the same shape as the input.

Key points

  • ReLU is provided as a dedicated Keras layer for applying rectified-linear activation behavior.
  • Its default transformation replaces negative values with zero while preserving positive values.
  • When max_value is configured, values at or above that limit are mapped to the cap.
  • Values between the threshold and upper limit pass through unchanged.
  • Values outside the pass-through interval use the configured negative-side slope.
  • Additional standard Layer options, including name and dtype, can be supplied through **kwargs.

Common mistakes

  • max_value must be nonnegative; leave it as None when the activation should not have an upper bound.
  • negative_slope must be nonnegative, and its default of zero removes the negative-side response.
  • threshold must be nonnegative; changing it alters where the thresholded behavior begins.

Example: Configuring ReLU behavior

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.

When to use it

Apply ordinary ReLU between layers using the default arguments.

Standard neural-network activation

Use a positive negative_slope to retain a scaled response below the threshold.

Leaky activation

Set max_value when activations must not exceed a specified ceiling.

Bounded activation

Raise threshold to change the boundary separating the below-threshold and pass-through regions.

Thresholded activation

Interview questions

QWhat does keras.layers.ReLU do by default?

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.

QWhat are the roles of max_value and negative_slope?

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.

QWhat are ReLU's input and output shape characteristics?

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.Activation
  • keras.activations.relu
  • keras.activations.relu6

Source: ReLU layer. Checked 2026-10-15.