Skip to content

Debugging

Meinrad Recheis edited this page Apr 10, 2019 · 5 revisions

Printing out the Graph

To print out a text representation of the current graph:

tf.train.export_meta_graph(@"sharp.meta.txt", as_text:true);

Doing this in both TensorFlow.NET and Python allows you to compare the graph nodes with a text diffing tool.

Graph Visualization using Tensorboard

To visualize the TensorFlow.NET-graph with Tensorboard, first export it as binary meta file:

tf.train.export_meta_graph(@"sharp.meta", as_text:false);

Then use Python to convert the meta format into an event file:

`import tensorflow tf=tensorflow

saver = tf.train.import_meta_graph("sharp.meta") writer = tf.summary.FileWriter(logdir="c:/tensorboard/logdir", graph=tf.get_default_graph()) # write to event writer.flush() `

Start Tensorboard:

tensorboard --logdir C:\tensorboard\logdir

Which will visualize the graph nicely.

tensorflow graph

The above graph is produced by this little pice of code:

var graph = tf.Graph().as_default(); with<Graph>(graph, g => { var x = constant_op.constant(10); var true_fn = new Func<Tensor>(() => { var (c_op, op_desc) = ops._create_c_op(g, ops._NodeDef("Identity", "cond/myop"), new[] { x }, new Operation[0]); return x; }); control_flow_ops.cond(x < 10, true_fn, () => x); });

Doing the same in Python is much easier, we can directly write the event file:

writer = tf.summary.FileWriter(logdir="D:/dev/tensorboard/logdir", graph=tf.get_default_graph()) # write to event writer.flush()

Comparing the viszalized graphs can make finding bugs a lot easier.

Clone this wiki locally