tf.keras.layers.TFSMLayer  |  TensorFlow v2.16.1 (original) (raw)

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

Inherits From: Layer, Operation

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

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:

Attributes
input Retrieves the input tensor(s) of a symbolic operation.Only returns the tensor(s) corresponding to the _first time_the operation was called.
output Retrieves the output tensor(s) of a layer.Only returns the tensor(s) corresponding to the _first time_the operation was called.

Methods

from_config

View source

@classmethod from_config( config )

Creates a layer from its config.

This method is the reverse of get_config, capable of instantiating the same layer from the config dictionary. It does not handle layer connectivity (handled by Network), nor weights (handled by set_weights).

Args
config A Python dictionary, typically the output of get_config.
Returns
A layer instance.

symbolic_call

View source

symbolic_call(
    *args, **kwargs
)