History

convert_from_tensorflow.py: add option to dump graph for visualization in tensorboard

Guo, Yejun committed 7 years ago

Commit 2c014341 parent aac382e2 files · +12 −7Browse files

Showing the changes to tools/python/convert_from_tensorflow.py (1 of 2 files). Show all

Unified · Split

tools/python/convert_from_tensorflow.py+7−6
@@ -24,10 +24,11 @@ import sys, struct · 23 unmodified lines
2424 __all__ = ['convert_from_tensorflow']
2525
2626 class TFConverter:
27− def __init__(self, graph_def, nodes, outfile):
27+ def __init__(self, graph_def, nodes, outfile, dump4tb):
2828 self.graph_def = graph_def
2929 self.nodes = nodes
3030 self.outfile = outfile
31+ self.dump4tb = dump4tb
3132 self.layer_number = 0
3233 self.output_names = []
3334 self.name_node_dict = {}
@@ -42,8 +43,8 @@ class TFConverter: · 8 unmodified lines
4243 def dump_for_tensorboard(self):
4344 graph = tf.get_default_graph()
4445 tf.import_graph_def(self.graph_def, name="")
45− # tensorboard --logdir=/tmp/graph
4646 tf.summary.FileWriter('/tmp/graph', graph)
47+ print('graph saved, run "tensorboard --logdir=/tmp/graph" to see it')
4748
4849
4950 def get_conv2d_params(self, node):
@@ -197,18 +198,18 @@ class TFConverter: · 147 unmodified lines
197198 self.remove_identity()
198199 self.generate_edges()
199200
200− #check the graph with tensorboard with human eyes
201− #self.dump_for_tensorboard()
201+ if self.dump4tb:
202+ self.dump_for_tensorboard()
202203
203204 self.dump_to_file()
204205
205206
206−def convert_from_tensorflow(infile, outfile):
207+def convert_from_tensorflow(infile, outfile, dump4tb):
207208 with open(infile, 'rb') as f:
208209 # read the file in .proto format
209210 graph_def = tf.GraphDef()
210211 graph_def.ParseFromString(f.read())
211212 nodes = graph_def.node
212213
213− converter = TFConverter(graph_def, nodes, outfile)
214+ converter = TFConverter(graph_def, nodes, outfile, dump4tb)
214215 converter.run()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t