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 model after it being loaded the second way.
Note: I want to use SavedModelBuilder
way because I train the model in Python and will use it at serving time in another language (Go), and it seems that SavedModelBuilder
is the only way in that case.
This works great with tf.train.Saver()
(first way):
model = tf.add(W * x, b, name="finalnode")
# save
saver = tf.train.Saver()
saver.save(sess, "/tmp/model")
# load
saver.restore(sess, "/tmp/model")
# IMPORTANT PART: REALLY USING THE MODEL AFTER LOADING IT
# I CAN'T FIND AN EQUIVALENT OF THIS PART IN THE OTHER WAY.
model = graph.get_tensor_by_name("finalnode:0")
sess.run(model, {x: [5, 6, 7]})
tf.saved_model.builder.SavedModelBuilder()
is defined in the Readme but after loading the model with tf.saved_model.loader.load(sess, [], export_dir)
), I can't find documentation on getting back at the nodes (see "finalnode"
in the code above)