Created
June 23, 2019 18:37
-
-
Save williamjshipman/cc44dbeb88f7edcbe72662aca56726a6 to your computer and use it in GitHub Desktop.
Simple functions for saving a TensorFlow graph as a SavedModel, followed by loading it again in TensorFlow 1.13.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def use_tf_saved_model(X, y, sess): | |
builder = tf.saved_model.builder.SavedModelBuilder('./data/save_model') | |
builder.add_meta_graph_and_variables( | |
sess, | |
[tf.saved_model.tag_constants.SERVING], | |
signature_def_map={ | |
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: tf.saved_model.predict_signature_def( | |
inputs={'X': X}, | |
outputs={'y': y} | |
) | |
}, | |
strip_default_attrs=True) | |
builder.save() | |
def load_tf_saved_model(sess, in_name, out_name): | |
tf.saved_model.load(sess, [tf.saved_model.tag_constants.SERVING], './data/save_model') | |
graph = tf.get_default_graph() | |
X = graph.get_tensor_by_name(in_name) | |
y = graph.get_tensor_by_name(out_name) | |
return X, y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment