tensorboardX: demo_graph.py error on pytorch 0.4.0

I tried running the demo_graph.py and got the following error.

python demo_graph.py 
Traceback (most recent call last):
  File "demo_graph.py", line 56, in <module>
    w.add_graph(model, (dummy_input, ))
  File "/home/dana/Desktop/tensorboard-pytorch/tensorboardX/writer.py", line 400, in add_graph
    self.file_writer.add_graph(graph(model, input_to_model, verbose))
  File "/home/dana/Desktop/tensorboard-pytorch/tensorboardX/graph.py", line 52, in graph
    trace, _ = torch.jit.trace(model, args)
TypeError: 'function' object is not iterable

The return of torch.jit.trace is this wrapper, from this commit

I’m using the Python 3.6 on Ubuntu 16.04

  • torch==0.4.0 built from source
  • tensorboardX==1.1
  • tensorboard==1.6.0

Edit: Updated my pytorch version

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 25 (8 by maintainers)

Most upvoted comments

Why is this issue closed? Was anyone able to reproduce the issue with pytorch 0.4?

@lanpa I have fixed my error, the code write network to tensorboard must before model.to(device)

model = torchvision.models.AlexNet(num_classes=10)
# 准备写tensorboard, 必须放在'.to(device)'之前,不然会报错
writer = SummaryWriter()
dummy_input = torch.autograd.Variable(torch.rand(1, 3, 227, 227))
writer.add_graph(model=model, input_to_model=(dummy_input, ))

model = model.to(device)

@lanpa Hi, I also tried running the demo_graph.py, but the graph on tensorboard is like graph I don’t know why it performs like this and how to correctly show the graphs of the networks. I’m using the Python 3.5 on Ubuntu 14.04

  • torch==0.3.1 from conda

  • tensorboardX=1.1

  • tensorboard =1.6.0

Edit: Wow, I missed the expanding button, so embarrassing =_=

@snehilverma41 notice the expect error here: line in the output. To my understanding, this error is expected. Check the source code.

Regarding your graph output, that seems like the correct graph for the LinearInLinear Module. To view graphs of other modules, try the run dropdown in tensorboard: tensorboard ui

demo_graph.py works perfectly. But if I try to save my own model it gives this error: Error occurs, checking if it's onnx problem... Your model fails onnx too, please report to onnx team No graph saved

Also is this bug rectified now?

@danakianfar Thank you so much! Because I just installed TensorboardX from source, I thought your pull request has been merged, but not yet. I tried your code, it works great.