LatestModuleExporter
Regularly exports registered modules into timestamped directories.
Modules can be registered to be exported by this class by calling register_module_for_export
when constructing the graph. The export_name
provided determines the subdirectory name used when exporting.
In addition to exporting, this class also garbage collects older exports.
Example use with EvalSpec:
train_spec = tf.estimator.TrainSpec(...) eval_spec = tf.estimator.EvalSpec( input_fn=eval_input_fn, exporters=[ hub.LatestModuleExporter("tf_hub", serving_input_fn), ]) tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
See LatestModuleExporter.export()
for a direct use example.
name
__init__
__init__( name, serving_input_fn, exports_to_keep=5 )
Creates an Exporter
to use with tf.estimator.EvalSpec
.
name
: unique name of this Exporter
, which will be used in the export path.serving_input_fn
: A function with no arguments that returns a ServingInputReceiver. This is used with the estimator
passed to export()
to build the graph (in PREDICT mode) that registers the modules for export. The model in that graph is never run, so the actual data provided by this input fn does not matter.exports_to_keep
: Number of exports to keep. Older exports will be garbage collected. Defaults to 5. Set to None to disable garbage collection.ValueError
: if any argument is invalid.export
export( estimator, export_path, checkpoint_path, eval_result=None, is_the_final_export=None )
Actually performs the export of registered Modules.
This method creates a timestamped directory under export_path
with one sub-directory (named export_name
) per module registered via register_module_for_export
.
Example use:
estimator = ... (Create estimator with modules registered for export)... exporter = hub.LatestModuleExporter("tf_hub", serving_input_fn) exporter.export(estimator, export_path, estimator.latest_checkpoint())
estimator
: the Estimator
from which to export modules.export_path
: A string containing a directory where to write the export timestamped directories.checkpoint_path
: The checkpoint path to export.eval_result
: Unused.is_the_final_export
: Unused.The path to the created timestamped directory containing the exported modules.
© 2018 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/hub/LatestModuleExporter