Skip to content
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:

importtensorflowtf=tensorflowsaver=tf.train.import_meta_graph("sharp.meta")
writer=tf.summary.FileWriter(logdir="c:/tensorboard/logdir", graph=tf.get_default_graph()) # write to eventwriter.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:

vargraph=tf.Graph().as_default();with<Graph>(graph, g =>{varx=constant_op.constant(10);vartrue_fn=newFunc<Tensor>(()=>{var(c_op,op_desc)=ops._create_c_op(g,ops._NodeDef("Identity","cond/myop"),new[]{x},newOperation[0]);returnx;});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 eventwriter.flush()

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

Clone this wiki locally