The question is about Tensorflow and its higher API Estimator and more generally about exporting and reusing models.
There exists several facilities to export a tensorflow models: tf.train.Saver, write and importing graph directly with their associated weights.
My interests lies in the tf.estimator.Estimator object and how we could reuse them. My use case is pretty simple: I fit a simple model say in tensorflow and would like to use its predictions in a more involved one.
There exists a export_savemodel method for serving the model, however I would need to make communication in my model through ports and I am not sure if this is optimal for training.
My question are the following:
Is there a (simple) way to use and import the output of
export_savemodelin python? I guessed you could technically use the C++ code and create wrapper around them?Is there an efficient way to compile an
tf.estimator.Estimatorand reuse it in Python? The XLA compiler seems be interesting, but I could not find out if I could use the result back in Python.Generally, what are the best practice on how to reuse previously trained models in Tensorflow?
Thanks a lot for your reading!
EDIT (my own answer): The accepted answer offers to use the saved_model API. However, I think it is worthwhile to understand the concept of graph and frozen graph. This gist link illustrates the main steps that are probably replicated in the saved_model api. Basically, you have to:
- rebuild the graph with redefined input ops;
- freeze this version;
- provide the new input to the
input_mapargument when callingtf.import_graph_defto reload the model backs.