question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trouble to use Tensorboard's add_graph with my network

See original GitHub issue

❓ Questions & Help

I am using code built upon this code example. Now I would like to add Tensorboard functionality.

Unfortunately, I am not able to get it work. I tried to adapt the insights from this tensorboard example provided at PyTorch Geometric’s repository.

Since the network expects a batch in the forward pass, I tried to use tensorboard.add_graph like this:


model = model.to(device)
for data in train_loader:
    data = data.to(device)
    model(data)
    break

writer.add_graph(model, data)

But then I get the following error message:

Type 'Tuple[Tuple[str, Tensor], Tuple[str, Tensor], Tuple[str, Tensor], Tuple[str, Tensor], Tuple[str, Tensor], Tuple[str, Tensor], Tuple[str, Tensor]]' cannot be traced. Only Tensors and (possibly nested) Lists, Dicts, and Tuples of Tensors can be traced (toTraceableStack at /opt/conda/conda-bld/pytorch_1579022030672/work/torch/csrc/jit/pybind_utils.h:305)

But the data I pass as a parameter to add_graph, next to the model should be some object, that can be forwarded through the network, shouldn’t it?

According to the tensorboard example I tried next:

model = model.to(device)
for data in train_loader:
    data = data.to(device)
    model(data)
    break

writer.add_graph(model, [data.x, data.edge_index])

But I get the following error message: TypeError: forward() takes 2 positional arguments but 3 were given

I really would like to now, how I can add my model to Tensorboard, since I would like to see, how the layers train and be able to do better debugging of my network.

Thank you in advance.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rusty1scommented, Aug 17, 2021

Tracing does not support arguments of arbitrary size. You should find the union set of arguments and pass them as optional parameters:

def forward(self, edge_index: Tensor, x: Optional[Tensor] = None, batch: Optional[Tensor] = None, ...):
    ...
1reaction
rusty1scommented, Apr 3, 2020

Yes, this is a PyTorch jit limitation, since it cannot handle custom objects as arguments. You need to modify the forward call of model to: def forward(self, x, edge_index).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trouble to use Tensorboard's add_graph with my network #1095
I am using code built upon this code example. Now I would like to add Tensorboard functionality. Unfortunately, I am not able to...
Read more >
Get started with TensorBoard - TensorFlow
It enables tracking experiment metrics like loss and accuracy, visualizing the model graph, projecting embeddings to a lower dimensional space, ...
Read more >
Graph Visualization Using TensorBoard | TensorFlow Tutorial
In addition, you will learn how to apply TensorFlow for backpropagation to tune the weights and biases while the Neural Networks are being ......
Read more >
Deep Dive Into TensorBoard: Tutorial With Examples
Visualize images in TensorBoard​​ In order to illustrate that, you need to convert the MNIST tensors to images using Matplotlib. After that, you...
Read more >
Using Tensorboard - Medium
This is a good way to see the quality of your network. ... The snippet below shows how to create a graph for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found