<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/layers/activations/activation.py#L6-L41) |

Applies an activation function to an output.

Inherits From: [`Layer`](https://www.tensorflow.org/api_docs/python/tf/keras/Layer), [`Operation`](https://www.tensorflow.org/api_docs/python/tf/keras/Operation)

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

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Mixed precision](https://www.tensorflow.org/guide/mixed_precision) - [Ragged tensors](https://www.tensorflow.org/guide/ragged_tensor) | - [Basic text classification](https://www.tensorflow.org/tutorials/keras/text_classification) - [Load text](https://www.tensorflow.org/tutorials/load_data/text) - [Classifying CIFAR-10 with XLA](https://www.tensorflow.org/xla/tf2xla/tutorials/autoclustering_xla) - [TFF simulations with accelerators](https://www.tensorflow.org/federated/tutorials/simulations_with_accelerators) - [Parametrized Quantum Circuits for Reinforcement Learning](https://www.tensorflow.org/quantum/tutorials/quantum_reinforcement_learning) |

<br />

<br />

<br />

| ## Args ||
|---|---|
| `activation` | Activation function. It could be a callable, or the name of an activation from the [`keras.activations`](https://www.tensorflow.org/api_docs/python/tf/keras/activations) namespace. |
| `**kwargs` | Base layer keyword arguments, such as `name` and `dtype`. |

<br />

#### Example:

    layer = keras.layers.Activation('relu')
    layer(np.array([-3.0, -1.0, 0.0, 2.0]))
    [0.0, 0.0, 0.0, 2.0]
    layer = keras.layers.Activation(keras.activations.relu)
    layer(np.array([-3.0, -1.0, 0.0, 2.0]))
    [0.0, 0.0, 0.0, 2.0]

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `input` | Retrieves the input tensor(s) of a symbolic operation. <br /> Only returns the tensor(s) corresponding to the *first time* the operation was called. |
| `output` | Retrieves the output tensor(s) of a layer. <br /> Only returns the tensor(s) corresponding to the *first time* the operation was called. |

<br />

## Methods

### `from_config`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/operation.py#L322-L362)

    @classmethod
    from_config(
        config
    )

Creates an operation from its config.

This method is the reverse of `get_config`, capable of instantiating the
same operation from the config dictionary.

> [!NOTE]
> **Note:** If you override this method, you might receive a serialized dtype config, which is a `dict`. You can deserialize it as follows:

    if "dtype" in config and isinstance(config["dtype"], dict):
        policy = dtype_policies.deserialize(config["dtype"])

<br />

<br />

<br />

| Args ||
|---|---|
| `config` | A Python dictionary, typically the output of `get_config`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| An operation instance. ||

<br />