Giter Club home page Giter Club logo

Comments (8)

miguelvr avatar miguelvr commented on April 27, 2024 1

your solution works, but that shouldn't make any difference lol

from tensorboardx.

lanpa avatar lanpa commented on April 27, 2024

Passing the variable directly to the model solved the problem. But I don't know why. XD
Does this bug happen only in v0.2?

import torch
import torch.nn as nn
from torch.autograd import Variable
from datetime import datetime
from tensorboard import SummaryWriter


model = nn.Linear(10, 10)

h = model(Variable(torch.rand(10, 10), requires_grad=True))

writer = SummaryWriter('runs/'+datetime.now().strftime('%B%d  %H:%M:%S'))

writer.add_graph(model, h)
writer.close()

from tensorboardx.

miguelvr avatar miguelvr commented on April 27, 2024

in theory it shouldn't be possible to add a graph in v0.1.12, right?

I tried with a nn.Sequential model and the result was the same.

from tensorboardx.

lanpa avatar lanpa commented on April 27, 2024

If your 0.1.12 is installed via pip then this function wont work. But if you build by yourself (0.1.12+xxxx) then it should work. Have you tried my solution?

from tensorboardx.

lucabergamini avatar lucabergamini commented on April 27, 2024

I found something..
if you write

x = Variable(torch.rand(10, 10), requires_grad=True)

model = nn.Linear(10, 10)

h = model(x)

writer = SummaryWriter('runs/'+datetime.now().strftime('%B%d  %H:%M:%S'))

writer.add_graph(model,h)
writer.close()

and check using the debug the lastVar.grad_fn.next_functions you will find the weight,the bias (as expected) but also the input, filled with the variable field, holding the matrix.
If you write

#x = Variable(torch.rand(10, 10), requires_grad=True)

model = nn.Linear(10, 10)

#h = model(x)

writer = SummaryWriter('runs/'+datetime.now().strftime('%B%d  %H:%M:%S'))

writer.add_graph(model,model(Variable(torch.rand(10, 10), requires_grad=True)))
writer.close()

The input is still an element of the tuple, but it has a variable field empty.Since we create a binding dict id2name with the id of the Parameters of the network, the input is not included. As such, in the first case the input is still evaluated in the make_name function as it hold the variable field, but there is no association with its id, producing the above error.
An easy way to fix it would be to check before insert using the id from id2name in the function make_name

from tensorboardx.

zhangmozhe avatar zhangmozhe commented on April 27, 2024

I update my pytorch to version 0.3, but I got the same error after my update. Previously there is no problem. Here is my code:

output_sample = model(Variable(torch.Tensor(1, 2, patch_size, patch_size).type(dtype), requires_grad=True), Variable(torch.Tensor(1, 1, patch_size, patch_size).type(dtype), requires_grad=True))
writer = SummaryWriter()
writer.add_graph(model, output_sample)

Even using the simple code I still get the error:

model = nn.Linear(10, 10)
h = model(Variable(torch.rand(10, 10), requires_grad=True))
writer = SummaryWriter()
writer.add_graph(model, h)
writer.close()

from tensorboardx.

lanpa avatar lanpa commented on April 27, 2024

That's expected behavior on v0.3. Please have a try on the onnx version: https://github.com/lanpa/tensorboard-pytorch/blob/master/onnx_graph.py
(you may need to install onnx as well)

from tensorboardx.

lanpa avatar lanpa commented on April 27, 2024

Since v0.2 is legacy, closing this.

from tensorboardx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.