from tensorflow.python.framework.graph_util import convert_variables_to_constants

saver = tf.train.Saver(tf.trainable_variables())
saver.restore(sess, "model.ckpt-100000")
graph = convert_variables_to_constants(sess,
sess.graph_def,
output_node_names=["predicts", "scores", "logits"])
with tf.gfile.FastGFile("the_model.pb", mode="wb") as f:
f.write(graph.SerializeToString())

TensorFlow版本:1.14 or 1.15