szagoruyko / pytorchviz

A small package to create visualizations of PyTorch execution graphs
MIT License
3.24k stars 279 forks source link

save problem #24

Open HiYellowC opened 6 years ago

HiYellowC commented 6 years ago

how can I save the output as png or jpg?

Honzys commented 5 years ago

Use:

dot.format = format
dot.render(filename)

where

soulslicer commented 4 years ago

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")
kamalravi commented 4 years ago

@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

You will get a "filename.png" image file. You can specify different format like 'svg' if you need.

ucalyptus commented 4 years ago

@kamalravi it gives ----> 7 dot.format("png") 8 dot.render("danet_model")

TypeError: 'str' object is not callable

AruniRC commented 4 years ago

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.