Giter Site home page Giter Site logo

Comments (6)

papy-ganjha avatar papy-ganjha commented on June 2, 2024 2

Hello,
You have to change the following :
_optimize_trace to _optimize_graph
in pytorch_builder.py line 71
I will if there is no pull request make one to fix this little bug
Hope it helps!

from hiddenlayer.

janspiegel avatar janspiegel commented on June 2, 2024

Hello, I have made this change manually in pytorch_builder.py but now get the below

`---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

in <cell line: 11>()
9 # see:#100
10 # Jupyter Notebook renders it automatically
---> 11 hl.build_graph(model_resnet, torch.zeros([4,3,256,256]).to(device))

2 frames

/usr/local/lib/python3.10/dist-packages/hiddenlayer/pytorch_builder.py in (.0)
80 op = torch_node.kind()
81 # Parameters
---> 82 params = {k: torch_node[k] for k in torch_node.attributeNames()}
83 # Inputs/outputs
84 # TODO: inputs = [i.unique() for i in node.inputs()]

TypeError: 'torch._C.Node' object is not subscriptable`

from hiddenlayer.

code-acrobat avatar code-acrobat commented on June 2, 2024

You need to hack more.

try:
  params = {k: torch_node[k] for k in torch_node.attributeNames()}
except Exception: 
  params = {}

If you follow various old tutorials with Jupyther notebooks you might need to change stuff like

hl.build_graph(model,torch.zeros([1]))

to

hl.build_graph(model,torch.zeros([1])).build_dot()

Hello, I have made this change manually in pytorch_builder.py but now get the below

`---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

in <cell line: 11>() 9 # see:#100 10 # Jupyter Notebook renders it automatically ---> 11 hl.build_graph(model_resnet, torch.zeros([4,3,256,256]).to(device))

2 frames

/usr/local/lib/python3.10/dist-packages/hiddenlayer/pytorch_builder.py in (.0) 80 op = torch_node.kind() 81 # Parameters ---> 82 params = {k: torch_node[k] for k in torch_node.attributeNames()} 83 # Inputs/outputs 84 # TODO: inputs = [i.unique() for i in node.inputs()]

TypeError: 'torch._C.Node' object is not subscriptable`

from hiddenlayer.

pikarpov avatar pikarpov commented on June 2, 2024

While that works, it also loses kernel size information from parameters to be included in the graph. Alternatively, you can follow the error and change __getitem__ to _node_get. To do that, include the following in the beginning of your pytorch_builder.py

# From https://github.com/pytorch/pytorch/blob/2efe4d809fdc94501fc38bf429e9a8d4205b51b6/torch/utils/tensorboard/_pytorch_graph.py#L384
def _node_get(node: torch._C.Node, key: str):
    """Gets attributes of a node which is polymorphic over return type."""
    sel = node.kindOf(key)
    return getattr(node, sel)(key)

torch._C.Node.__getitem__ = _node_get

Now, you should be able to extract from the nodes just fine, so there should be no issues with this line.

params = {k: torch_node[k] for k in torch_node.attributeNames()}

Credit: TypeError: 'torch._C.Node' object is not subscriptable

from hiddenlayer.

annahedstroem avatar annahedstroem commented on June 2, 2024

+1 with the same problem

from hiddenlayer.

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.