pytorchviz
pytorchviz copied to clipboard
save problem
how can I save the output as png or jpg?
Use:
dot.format = format
dot.render(filename)
where
-
dot
is graph representation return usingmake_dot
-
format
is format fromgraphviz
(see https://graphviz.readthedocs.io/en/stable/manual.html#formats) -
filename
specifies path, where to save graph
I tried to do that and the image I get is nonetype:
disp = model(imgL,imgR)
dot = make_dot(disp)
print(dot)
dot.render("test.png")
@soulslicer Try like this
x = torch.zeros(1, 3, 224, 224, dtype=torch.float, requires_grad=False) out = model(x) dot=make_dot(out) print(dot) dot.format = 'png' dot.render("filename")
where
- x is your input
- model is your deep model (e.g. resnet)
You will get a "filename.png" image file. You can specify different format like 'svg' if you need.
@kamalravi it gives
----> 7 dot.format("png")
8 dot.render("danet_model")
TypeError: 'str' object is not callable
I think a full example for saving might be helpful, especially for those not immediately familiar with graphviz.
dot = torchviz.make_dot(y.mean(), params=dict(model.named_parameters()))
dot.format = 'png'
dot.render('torchviz-sample')
And the image is saved under the current working directory as torchviz-sample.png
.