Skip to content

Instantly share code, notes, and snippets.

@vsuthichai
Created August 7, 2018 22:57
Show Gist options
  • Select an option

  • Save vsuthichai/3f24222417dbe323ee5f29d367056817 to your computer and use it in GitHub Desktop.

Select an option

Save vsuthichai/3f24222417dbe323ee5f29d367056817 to your computer and use it in GitHub Desktop.
def load_graph(graph_filename):
with open(graph_filename, 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Graph().as_default() as graph:
tf.import_graph_def(graph_def)
return graph
def print_nodes(graph):
for node in graph.as_graph_def().node:
print(node.name, node.op)
def print_ops(graph):
for op in graph.get_operations():
for inp in op.inputs:
print(" Input {}".format(inp))
print('- {0:20s} "{1}" ({2} outputs) {3}'.format(op.type, op.name, len(op.outputs), op.outputs))
def main():
graph = load_graph("frozen.pb")
print_nodes(graph)
print_ops(graph)
input_node_0 = graph.get_tensor_by_name('import/IteratorGetNext_1:0')
input_node_1 = graph.get_tensor_by_name('import/IteratorGetNext_1:1')
input_node_2 = graph.get_tensor_by_name('import/IteratorGetNext_1:2')
input_node_3 = graph.get_tensor_by_name('import/IteratorGetNext_1:3')
output_node = graph.get_tensor_by_name('import/ForwardPass_1/transformer_decoder/decode/strided_slice_19:0')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment