0

I was given a TensorFlow checkpoint and also an exported model, but to serve a model using Google ML Cloud, I need a saved_model.pbtxt file. It seems that I need to load the checkpoint and use SavedModelBuilder but SavedModelBuilder wants a dictionary of the names of the input and output nodes.

My question is, given the checkpoint or the exported model (below), how can I find the names of the nodes needed to generate the pbtxt file I need to serve the model via Google's ML Cloud service?

checkpoint
export.data-00000-of-00001
export.index
export.meta
options.json
jkschin
  • 5,776
  • 6
  • 35
  • 62
blueether
  • 3,666
  • 4
  • 26
  • 32

1 Answers1

1

The export.meta should be a MetaGraphDef proto. So you should be able to parse the proto to get the graph. You can then search through the nodes to find the node of interest.

Something like:

import argparse
from tensorflow.core.protobuf import meta_graph_pb2 
import logging

if __name__ == "__main__":
  parser = argparse.ArgumentParser(
      description='Argument parser.')  
  parser.add_argument('--path',
                      required=True,
                      help='The path to the metadata graph file.')
  args = parser.parse_args()                      
  with open(args.path, 'r') as hf:
    graph = meta_graph_pb2.MetaGraphDef.FromString(hf.read())
  print "graph: \n{0}".format(graph)

I think you should also be able to point TensorBoard at the directory containing that file and TensorBoard will render the graph and use that to identify the names of the input/output nodes.

jkschin
  • 5,776
  • 6
  • 35
  • 62
Jeremy Lewi
  • 6,386
  • 6
  • 22
  • 37
  • Thanks for this, this was incredibly helpful! Just one more question, forgive my ignorance but how does one interpret this file? Are the inputs and outputs of the whole graph in a specific location or is there some documentation that provides details on the formatting? – blueether Jul 14 '17 at 17:01
  • So typically you have access to the source code and you can just look at the code to see what names are given to inputs/outputs. If you want to identify the inputs/outputs from export.meta you need to do some work. I think TensorBoard allows you to visualize the graph. At which point you can identify visually the inputs/outputs and get the names. There might be additional tooling somewhere in the TF codebase. – Jeremy Lewi Jul 14 '17 at 18:35