Skip to content

Instantly share code, notes, and snippets.

@dkurt
Last active October 17, 2017 14:27
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 dkurt/ff1b2dd272e544e6873c54d3a571662a to your computer and use it in GitHub Desktop.
Save dkurt/ff1b2dd272e544e6873c54d3a571662a to your computer and use it in GitHub Desktop.
import tensorflow as tf
# Read the graph.
with tf.gfile.FastGFile('opt_graph.pb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
# Remove Const nodes.
for i in reversed(range(len(graph_def.node))):
if graph_def.node[i].op == 'Const':
del graph_def.node[i]
for attr in ['T', 'data_format', 'Tshape', 'N', 'Tidx', 'Tdim',
'use_cudnn_on_gpu', 'Index', 'Tperm', 'is_training',
'Tpaddings']:
if attr in graph_def.node[i].attr:
del graph_def.node[i].attr[attr]
# Save as text.
tf.train.write_graph(graph_def, "", "text_graph.pbtxt", as_text=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment