ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more

tf.contrib.estimator.export_saved_model_for_mode

View source on GitHub

Exports a single train/eval/predict graph as a SavedModel. (deprecated)

For a detailed guide, see Using SavedModel with Estimators.

Sample usage:

classifier = tf.estimator.LinearClassifier(
    feature_columns=[age, language])
classifier.train(input_fn=input_fn, steps=1000)

feature_spec = {
    'age': tf.placeholder(dtype=tf.int64),
    'language': array_ops.placeholder(dtype=tf.string)
}
label_spec = tf.placeholder(dtype=dtypes.int64)

train_rcvr_fn = tf.contrib.estimator.build_raw_supervised_input_receiver_fn(
    feature_spec, label_spec)

export_dir = tf.contrib.estimator.export_saved_model_for_mode(
    classifier,
    export_dir_base='my_model/',
    input_receiver_fn=train_rcvr_fn,
    mode=model_fn_lib.ModeKeys.TRAIN)

# export_dir is a timestamped directory with the SavedModel, which
# can be used for serving, analysis with TFMA, or directly loaded in.
with ops.Graph().as_default() as graph:
  with session.Session(graph=graph) as sess:
    loader.load(sess, [tag_constants.TRAINING], export_dir)
    weights = graph.get_tensor_by_name(''linear/linear_model/age/weights')
    ...

This method is a wrapper for _export_all_saved_models, and wraps a raw input_receiver_fn in a dictionary to pass in to that function. See _export_all_saved_models for full docs.

See tf.contrib.estimator.export_saved_model_for_mode for the currently exposed version of this function.

estimator an instance of tf.estimator.Estimator
export_dir_base A string containing a directory in which to create timestamped subdirectories containing exported SavedModels.
input_receiver_fn a function that takes no argument and returns the appropriate subclass of InputReceiver.
assets_extra A dict specifying how to populate the assets.extra directory within the exported SavedModel, or None if no extra assets are needed.
as_text whether to write the SavedModel proto in text format.
checkpoint_path The checkpoint path to export. If None (the default), the most recent checkpoint found within the model directory is chosen.
mode tf.estimator.ModeKeys value indicating with mode will be exported.

The string path to the exported directory.

ValueError if input_receiver_fn is None, no export_outputs are provided, or no checkpoint can be found.