Error: 'Digraph' object has no attribute '_repr_svg_'. How do I solve this?

Viewed 521

I was following a course on Pytorch and I'm having this error, when in the video everything is perfect, even though the code is the same:

import hiddenlayer as hl

model1 = torch.nn.Sequential(torch.nn.Linear(inp, hid),
                             torch.nn.Linear(hid, out))

where inp=1, out=1 and hid=100

hl.build_graph(model1, torch.zeros([10,1]))

Which outputs this error:

AttributeError                            Traceback (most recent call last)
~\anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

~\anaconda3\lib\site-packages\hiddenlayer\graph.py in _repr_svg_(self)
    357     def _repr_svg_(self):
    358         """Allows Jupyter notebook to render the graph automatically."""
--> 359         return self.build_dot()._repr_svg_()
    360 
    361     def save(self, path, format="pdf"):

AttributeError: 'Digraph' object has no attribute '_repr_svg_'

<hiddenlayer.graph.Graph at 0x21c5c1939a0>

I tried to find a solution on the hiddenlayer library's GitHub page (https://github.com/waleedka/hiddenlayer) but I couldn't find any... I'm thinking that it might be a version issue, since the course I'm following was released in 2019

1 Answers
hl.build_graph(model, t.zeros([10, 1])).build_dot()

This is what you need. You need to add ".build_dot()"

Related