Load a SavedModel from export_dir.

Used in the notebooks

Used in the guide Used in the tutorials

Signatures associated with the SavedModel are available as functions:

imported = tf.saved_model.load(path)
f = imported.signatures["serving_default"]

Objects exported with additionally have trackable objects and functions assigned to attributes:

exported = tf.train.Checkpoint(v=tf.Variable(3.))
exported.f = tf.function(
    lambda x: exported.v * x,
    input_signature=[tf.TensorSpec(shape=None, dtype=tf.float32)]), path)
imported = tf.saved_model.load(path)
assert 3. == imported.v.numpy()
assert 6. == imported.f(x=tf.constant(2.)).numpy()

Loading Keras models

Keras models are trackable, so they can be saved to SavedModel. The object returned by tf.saved_model.load is not a Keras object (i.e. doesn't have .fit, .predict, etc. methods). A few attributes and functions are still available: .variables, .trainable_variables and .__call__.

model = tf.keras.Model(...), path)
imported = tf.saved_model.load(path)
outputs = imported(inputs)

Use tf.keras.models.load_model to restore the Keras model.

Importing SavedModels from TensorFlow 1.x

SavedModels from tf.estimator.Estimator or 1.x SavedModel APIs have a flat graph instead of tf.function objects. These SavedModels will be loaded with the following attributes:

  • .signatures: A dictionary mapping signature names to functions.
  • .prune(feeds, fetches): A method w