<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/ops/function.py#L11-L253) |

Class that encapsulates a computation graph of Keras operations.

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

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.keras.Function`](https://www.tensorflow.org/api_docs/python/tf/keras/Function)

<br />

    tf.keras.Function(
        inputs, outputs, name=None
    )

You can use a `Function` to capture the computation graph linking
some input tensors to some output tensors, and reapply the same
computation on new inputs.

A `Function` is similar to a Functional Model, with the difference
that it is stateless (it does not track state variables)
and does not implement the `Layer` API.

#### Example:

    input_1 = keras.KerasTensor(shape=(None, 2, 3))
    input_2 = keras.KerasTensor(shape=(None, 2, 3))
    x = input_1 + input_2
    output = keras.ops.sigmoid(x)
    fn = keras.Function(inputs=[input_1, input_2], outputs=output)

    input_1_val = np.random.random((4, 2, 3))
    input_2_val = np.random.random((4, 2, 3))
    output_val = fn([input_1_val, input_2_val])

<br />

<br />

<br />

| ## Args ||
|---|---|
| `inputs` | `KerasTensor` instance or nested structured of `KerasTensor` instances. |
| `outputs` | `KerasTensor` instance or nested structured of `KerasTensor` instances. They should be computable given only the values of `inputs`. |
| `name` | String. The name of the function. |

<br />

<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. |
| `inputs` | Flat list of the symbolic inputs of the Function. |
| `operations` | <br /> <br /> |
| `output` | Retrieves the output tensor(s) of a layer. <br /> Only returns the tensor(s) corresponding to the *first time* the operation was called. |
| `outputs` | Flat list of the symbolic outputs of the Function. |

<br />

## Methods

### `call`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/function.py#L168-L171)

    call(
        inputs
    )

Computes output tensors for new inputs.

### `compute_output_shape`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/function.py#L154-L166)

    compute_output_shape(
        input_shape
    )

### `compute_output_spec`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/function.py#L132-L152)

    compute_output_spec(
        inputs
    )

### `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 />

### `get_config`

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

    get_config()

Returns the config of the object.

An object config is a Python dictionary (serializable)
containing the information needed to re-instantiate it.

### `quantized_call`

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

    quantized_call(
        *args, **kwargs
    )

### `rematerialized_call`

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

    rematerialized_call(
        fn, *args, **kwargs
    )

Enable rematerialization dynamically for an operation's call method.

<br />

<br />

<br />

| Args ||
|---|---|
| `fn` | The original `call` or `quantized_call` method of an operation. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Rematerialized method. ||

<br />

### `symbolic_call`

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

    symbolic_call(
        *args, **kwargs
    )

### `__call__`

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

    __call__(
        *args, **kwargs
    )

Call self as a function.