Get computation graph in tensorboard

How do I display computation graph in tensorboard from pytorch?

I logged my output images to tensorboard as follows:

import tensorflow as tf
self.tf = tf
self.writer = tf.summary.FileWriter('path/to/log/dir')
img_summaries = []
...
for label, image_numpy in visuals.items():
    try:
      s = StringIO()
   except:
      s = BytesIO()
   scipy.misc.toimage(image_numpy).save(s, format="jpeg")
   img_sum = self.tf.Summary.Image(encoded_image_string=s.getvalue(), height=image_numpy.shape[0], width=image_numpy.shape[1])
   img_summaries.append(self.tf.Summary.Value(tag=label, image=img_sum))
   summary = self.tf.Summary(value=img_summaries)
   self.writer.add_summary(summary, step)

But when I try to add graph to tensorboard:

writer.add_graph(model, loss_1)

I get this error:

raise TypeError("The passed graph must be an instance of `Graph` "
TypeError: The passed graph must be an instance of `Graph` or the deprecated `GraphDef`
>>> print(torch.__version__)
0.3.0.post4
>>> print(tensorflow.__version__)
1.4.1

What am I doing wrong here? Any help is appreciated. Thank you.

Hi,

A pytorch model is not the same thing as a tensorboard Graph object. Unless you recreate a tensorflow Graph similar to your model you can’t do that. And even doing that might be tricky as there are some operations that are not the same between the two frameworks.
Maybe something like tensorboard-pytorch could help you.

2 Likes