导出导入graph模块
graph = tf.Graph()
with tf.Session(graph=graph) as sess:
sess.run(tf.global_variables_initializer())
restore_saver.restore(sess, ckpt)
inputs = {input_key: tf.saved_model.utils.build_tensor_info(input_image)}
outputs = {output_key: tf.saved_model.utils.build_tensor_info(output_image)}
signature = tf.saved_model.signature_def_utils.build_signature_def(inputs, outputs, method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME)
builder = tf.saved_model.builder.SavedModelBuilder(export_name)
builder.add_meta_graph_and_variables(sess, [SERVER], {signature_key:signature})
builder.save()
导出
signature_key = tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY
graph = tf.Graph()
with tf.Session() as sess:
meta_graph_def = tf.saved_model.loader.load(sess, [tf.saved_model.tag_constants.SERVING], model_name)
signature = meta_graph_def.signature_def
x_tensor_name = signature[signature_key].inputs[‘input_key’].name
y_tensor_name = signature[signature_key].outputs[‘output_key’].name
x = sess.graph.get_tensor_by_name(x_tensor_name)
y = sess.graph.get_tensor_by_name(y_tensor_name)
output_value = sess.run(y, feed_dict={x: input_value})
阅读(2100) | 评论(0) | 转发(0) |