Skip to content

Instantly share code, notes, and snippets.

@nqbao
Created January 26, 2017 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nqbao/98a5706d0258477f493174f0d72edfe5 to your computer and use it in GitHub Desktop.
Save nqbao/98a5706d0258477f493174f0d72edfe5 to your computer and use it in GitHub Desktop.
read serving signatures from tensorflow
# XXX: this only works for tf 0.11
import tensorflow as tf
from tensorflow.core.protobuf import meta_graph_pb2
from tensorflow.contrib.session_bundle import manifest_pb2
def read_serving_signatures(meta_file):
tf.reset_default_graph()
with tf.Session() as sess:
new_saver = tf.train.import_meta_graph(meta_file)
graph = tf.get_default_graph()
# print(graph.get_all_collection_keys())
pb = graph.get_collection("serving_signatures")[0]
signatures = manifest_pb2.Signatures()
pb.Unpack(signatures)
return signatures
def read_meta_graph(meta_file):
meta_graph = meta_graph_pb2.MetaGraphDef()
with open(meta_file, "rb") as f:
meta_graph.ParseFromString(f.read())
return meta_graph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment