<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/export/tfsm_layer.py#L9-L182) |

Reload a Keras model/layer that was saved via SavedModel / ExportArchive.

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.TFSMLayer(
        filepath,
        call_endpoint='serve',
        call_training_endpoint=None,
        trainable=True,
        name=None,
        dtype=None
    )

<br />

<br />

<br />

| ## Arguments ||
|---|---|
| `filepath` | `str` or `pathlib.Path` object. The path to the SavedModel. |
| `call_endpoint` | Name of the endpoint to use as the `call()` method of the reloaded layer. If the SavedModel was created via `model.export()`, then the default endpoint name is `'serve'`. In other cases it may be named `'serving_default'`. |

<br />

#### Example:

    model.export("path/to/artifact")
    reloaded_layer = TFSMLayer("path/to/artifact")
    outputs = reloaded_layer(inputs)

The reloaded object can be used like a regular Keras layer, and supports
training/fine-tuning of its trainable weights. Note that the reloaded
object retains none of the internal structure or custom methods of the
original object -- it's a brand new layer created around the saved
function.

**Limitations:**

- Only call endpoints with a single `inputs` tensor argument (which may optionally be a dict/tuple/list of tensors) are supported. For endpoints with multiple separate input tensor arguments, consider subclassing `TFSMLayer` and implementing a `call()` method with a custom signature.
- If you need training-time behavior to differ from inference-time behavior (i.e. if you need the reloaded object to support a `training=True` argument in `__call__()`), make sure that the training-time call function is saved as a standalone endpoint in the artifact, and provide its name to the `TFSMLayer` via the `call_training_endpoint` argument.

<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/export/tfsm_layer.py#L151-L182)

    @classmethod
    from_config(
        config, custom_objects=None, safe_mode=None
    )

Creates a TFSMLayer from its config.

<br />

<br />

<br />

| Args ||
|---|---|
| `config` | A Python dictionary, typically the output of `get_config`. |
| `custom_objects` | Optional dictionary mapping names to custom objects. |
| `safe_mode` | Boolean, whether to disallow loading TFSMLayer. When `safe_mode=True`, loading is disallowed because TFSMLayer loads external SavedModels that may contain attacker-controlled executable graph code. Defaults to `True`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A TFSMLayer instance. ||

<br />