I have found 2 ways to save a model in Tensorflow: tf.train.Saver()
and SavedModelBuilder
. However, I can\'t find documentation on using the mo
What was missing was the signature
# Saving
builder = tf.saved_model.builder.SavedModelBuilder(export_dir)
builder.add_meta_graph_and_variables(sess, ["tag"], signature_def_map= {
"model": tf.saved_model.signature_def_utils.predict_signature_def(
inputs= {"x": x},
outputs= {"finalnode": model})
})
builder.save()
# loading
with tf.Session(graph=tf.Graph()) as sess:
tf.saved_model.loader.load(sess, ["tag"], export_dir)
graph = tf.get_default_graph()
x = graph.get_tensor_by_name("x:0")
model = graph.get_tensor_by_name("finalnode:0")
print(sess.run(model, {x: [5, 6, 7, 8]}))