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

TensorFlow · Class

layers.Activation

A Keras layer that applies a chosen activation function to its input. The activation can be specified by supported name or passed as a callable.

How it works

Activation is a Keras layer that transforms its input by applying the function supplied at construction. The function may be identified by a supported activation name or provided directly as a callable, while standard layer options can be passed through keyword arguments.

Syntax

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

Parameters

NameTypeDescription
activationcallable or strActivation function; either a callable or the name of an activation from the keras.activations namespace.
**kwargskeyword argumentsBase layer keyword arguments, such as name and dtype.

Returns

A layer whose call applies the configured activation function to its input.

Key points

  • The layer transforms an output by applying the configured activation function.
  • Additional keyword arguments are forwarded as standard Keras layer configuration, including naming and dtype options.
  • A built-in activation can be selected with its string name.
  • The activation can instead be supplied as a function object.
  • With ReLU, negative inputs produce zero and the positive example remains unchanged.

Common mistakes

  • The activation argument must be either a callable or the name of an activation available in the Keras activations namespace.

Example: Apply ReLU with an Activation layer

import tensorflow as tf

layer = tf.keras.layers.Activation("relu")
print(layer([-3.0, -1.0, 0.0, 2.0]).numpy())

Creates a ReLU activation layer and applies it to a tensor-like input.

When to use it

Insert a standard activation

Adding a nonlinear transformation after another layer or operation.

Wrap a callable

Reusing a custom transformation inside a Keras model.

Set layer metadata and dtype

Configuring a layer consistently with other Keras components.

Interview questions

QWhat does tf.keras.layers.Activation do?

Activation is a Keras layer that applies a specified activation function to its input. The function can be supplied as a callable or selected by name from the Keras activations namespace.

Follow-up: How would you make the layer serializable in a model configuration? Use a registered or supported activation name when possible, and ensure any custom callable is compatible with Keras serialization.

QWhat arguments does Activation accept?

The required activation argument identifies the transformation. The constructor also accepts base-layer keyword arguments, including options such as name and dtype.

Follow-up: What is the practical difference between passing a function object and a string? A callable gives direct function control, while a supported name lets Keras resolve the activation by namespace name.

QHow does an Activation layer behave when called?

Calling the layer applies the configured function elementwise or according to the semantics of that function. For example, a ReLU layer maps negative values to zero while leaving positive values unchanged.

Follow-up: Can the layer be used with symbolic tensors in a Functional model? Yes; as a Keras Layer, it can participate in symbolic model construction and expose symbolic inputs and outputs.

  • tf.keras.Layer
  • tf.keras.activations.relu
  • tf.keras.layers.Softmax
  • tf.keras.layers.PReLU

Source: tf.keras.layers.Activation | TensorFlow v2.16.1. Checked 2026-10-15.