Skip to content

Instantly share code, notes, and snippets.

@lukmanr
Last active October 29, 2018 20:59
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 lukmanr/5bbac6ef9c5b49c600475e5b4628d254 to your computer and use it in GitHub Desktop.
Save lukmanr/5bbac6ef9c5b49c600475e5b4628d254 to your computer and use it in GitHub Desktop.
TF Model Optimization code 3
def describe_graph(graph_def, show_nodes=False):
print('Input Feature Nodes: {}'.format(
[node.name for node in graph_def.node if node.op=='Placeholder']))
print('')
print('Unused Nodes: {}'.format(
[node.name for node in graph_def.node if 'unused' in node.name]))
print('')
print('Output Nodes: {}'.format(
[node.name for node in graph_def.node if (
'predictions' in node.name or 'softmax' in node.name)]))
print('')
print('Quantization Nodes: {}'.format(
[node.name for node in graph_def.node if 'quant' in node.name]))
print('')
print('Constant Count: {}'.format(
len([node for node in graph_def.node if node.op=='Const'])))
print('')
print('Variable Count: {}'.format(
len([node for node in graph_def.node if 'Variable' in node.op])))
print('')
print('Identity Count: {}'.format(
len([node for node in graph_def.node if node.op=='Identity'])))
print('', 'Total nodes: {}'.format(len(graph_def.node)), '')
if show_nodes==True:
for node in graph_def.node:
print('Op:{} - Name: {}'.format(node.op, node.name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment