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

Keras · Class

layers.Activation

Keras layers.Activation applies a selected activation function as a layer. Choose a built-in activation by name or provide a callable.

How it works

Activation wraps a chosen activation function as a Keras layer. The function can be selected by its built-in string name or supplied directly as a callable, and the layer applies it to the input while preserving the input shape.

Syntax

keras.layers.Activation(activation, **kwargs)

Parameters

NameTypeDescription
activationcallable or stringActivation function, supplied as a callable or as the name of an activation in the keras.activations namespace.
**kwargskeyword argumentsBase layer keyword arguments, such as name and dtype.

Returns

A tensor produced by applying the selected activation function to the input; the documented example shows the transformed output.

Key points

  • Activation is a Keras layer that applies an activation function to an output.
  • The activation can be either a callable or a built-in activation name.
  • Additional keyword arguments are forwarded as standard Layer options, including name and dtype.
  • A built-in activation can be selected with the string name relu.
  • The corresponding activation function can instead be passed directly as a callable.

Common mistakes

  • A string must identify an activation available in the keras.activations namespace; otherwise pass a callable.

Example: Apply ReLU with an Activation layer

import keras
import numpy as np

layer = keras.layers.Activation("relu")
output = layer(np.array([-3.0, -1.0, 0.0, 2.0]))
print(output)

Creates a ReLU activation layer and applies it element-wise to a NumPy array.

When to use it

Explicit activation stage

Add a named activation as an explicit layer after another layer in a model.

Built-in activation

Use a built-in activation such as ReLU without writing the function manually.

Custom callable

Apply a user-defined tensor transformation supplied as a callable.

Interview questions

QWhat can the activation argument contain?

The constructor accepts an activation and arbitrary base-layer keyword arguments. The activation may be a callable or the name of an activation in the keras.activations namespace.

Follow-up: How would you express the same operation in a Dense layer? Pass the activation through Dense's activation argument instead of adding a separate Activation layer.

QWhat does keras.layers.Activation do?

The layer applies the selected activation function to its input output. For example, a ReLU layer maps negative values to zero, as shown by the documented example.

Follow-up: Can the activation be custom? Yes, provide a callable that accepts a tensor and returns the transformed tensor.

QHow does Activation compare with using Dense(..., activation=...)?

Activation is useful when the activation should be represented as its own layer. Keras also supports passing activations through the activation argument of forward layers such as Dense.

Follow-up: When is the separate layer especially useful? It makes the transformation explicit in a sequential architecture or lets it be inserted after another layer.

  • keras.activations.relu
  • keras.layers.Dense
  • keras.layers.ReLU

Source: Activation Layer. Checked 2026-10-15.