Insert a standard activation
Adding a nonlinear transformation after another layer or operation.
TensorFlow · Class
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.
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.
tf.keras.layers.Activation(activation, **kwargs)| Name | Type | Description |
|---|---|---|
activation | callable or str | Activation function; either a callable or the name of an activation from the keras.activations namespace. |
**kwargs | keyword arguments | Base layer keyword arguments, such as name and dtype. |
A layer whose call applies the configured activation function to its input.
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.
Adding a nonlinear transformation after another layer or operation.
Reusing a custom transformation inside a Keras model.
Configuring a layer consistently with other Keras components.
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.
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.
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.Layertf.keras.activations.relutf.keras.layers.Softmaxtf.keras.layers.PReLU