tf1.12
checkpoints like :
we should know our input and output layers’ name:
now the code to make the pb is:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
save_dir = 'checkpoints/'
save_path = os.path.join(save_dir, 'best_validation')
graph = tf.Graph()
with tf.Session(graph=graph) as sess:
# Restore from checkpoint
loader = tf.train.import_meta_graph(save_path + '.meta')
loader.restore(sess, save_path)
x = tf.get_default_graph().get_tensor_by_name('input_x:0')
keep_prob = tf.get_default_graph().get_tensor_by_name('keep_prob:0')
y = tf.get_default_graph().get_tensor_by_name('score/softmax:0')
export_path = 'data/pb/'
builder = tf.saved_model.builder.SavedModelBuilder(export_path)
signature = tf.saved_model.signature_def_utils.predict_signature_def(
inputs={'input': x, 'keep_prob':keep_prob}, outputs={'output':y}
)
# using custom tag instead of: tags=[tf.saved_model.tag_constants.SERVING]
builder.add_meta_graph_and_variables(sess=sess,
tags=[tf.saved_model.tag_constants.SERVING],
signature_def_map={'clf': signature})
builder.save()
just do it.
,请赠一朵玫瑰。❤❤❤❤