Skip to content

Instantly share code, notes, and snippets.

@luuil
Created November 6, 2019 08:50
Show Gist options
  • Save luuil/fe7c7ff8d56cdbebebc16d008ee1ddbd to your computer and use it in GitHub Desktop.
Save luuil/fe7c7ff8d56cdbebebc16d008ee1ddbd to your computer and use it in GitHub Desktop.
show information in tensorflow graph def
def describe_graph(graph_def, show_nodes=False):
from collections import Counter
c = Counter(map(lambda n: n.op, graph_def.node))
print(c)
print('Input Nodes: {}'.format([node.name for node in graph_def.node if node.op == 'Placeholder']))
output_nodes = [node.name for node in graph_def.node if (
'predictions' in node.name or 'softmax' in node.name or 'concat' in node.name)]
print(f'Output Nodes: {output_nodes}')
print('Unused Nodes: {}'.format([node.name for node in graph_def.node if 'unused' in node.name]))
quant_nodes = [node.name for node in graph_def.node if 'quant' in node.name]
print(f'Quantization Nodes: {len(quant_nodes)}: {quant_nodes}')
print('Variable Count: {}'.format(len([node for node in graph_def.node if 'Variable' in node.op])))
print('', 'Total nodes: {}'.format(len(graph_def.node)), '')
if show_nodes:
print(*list(map(lambda n: (n.op, n.name), graph_def.node)), sep="\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment