Skip to content

Instantly share code, notes, and snippets.

@mdobson
Created July 9, 2018 11:45
Show Gist options
  • Save mdobson/15b4656fdbb1c98b1c0863a24e4dcd04 to your computer and use it in GitHub Desktop.
Save mdobson/15b4656fdbb1c98b1c0863a24e4dcd04 to your computer and use it in GitHub Desktop.

Revisions

  1. mdobson created this gist Jul 9, 2018.
    19 changes: 19 additions & 0 deletions 1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    import tensorflow as tf
    import sys
    from tensorflow.python.platform import gfile

    from tensorflow.core.protobuf import saved_model_pb2
    from tensorflow.python.util import compat

    with tf.Session() as sess:
    model_filename = 'ssdlite_mobilenet_v2_coco_2018_05_09/saved_model/saved_model.pb'
    with gfile.FastGFile(model_filename, 'rb') as f:
    data = compat.as_bytes(f.read())
    sm = saved_model_pb2.SavedModel()
    sm.ParseFromString(data)
    if 1 != len(sm.meta_graphs):
    print('More than one graph found.')
    sys.exit(1)

    #g_in = tf.import_graph_def(sm.meta_graphs[0].graph_def)
    [print(n.name) for n in sm.meta_graphs[0].graph_def.node]