View source on GitHub

Represents a file asset to hermetically include in a SavedModel.

A SavedModel can include arbitrary files, called assets, that are needed for its use. For example a vocabulary file used initialize a lookup table.

When a trackable object is exported via, all the Assets reachable from it are copied into the SavedModel assets directory. Upon loading, the assets and the serialized functions that depend on them will refer to the correct filepaths inside the SavedModel directory.


filename = tf.saved_model.Asset("file.txt")

def func():

trackable_obj = tf.train.Checkpoint()
trackable_obj.func = func
trackable_obj.filename = filename, "/tmp/saved_model")

# The created SavedModel is hermetic, it does not depend on
# the original file and can be moved to another path."file.txt")"/tmp/saved_model", "/tmp/new_location")

reloaded_obj = tf.saved_model.load("/tmp/new_location")

asset_path A 0-D tf.string tensor with path to the asset.