mert-kurttutan / torchview

torchview: visualize pytorch models
https://torchview.dev
MIT License
822 stars 37 forks source link

save_graph_format #64

Closed turian closed 1 year ago

turian commented 1 year ago

Is your feature request related to a problem? Please describe.

I am getting PNGs with graph_dir=LR that are too small to read.

Describe the solution you'd like I'd like save_graph_format so I could output "svg" or "PDF" or other formats that graphviz supports.

Describe alternatives you've considered Forking and hacking the format so it's not always PNG.

Screenshots / Text

My graph is 4839 x 325, which is just too small to read.

image

mert-kurttutan commented 1 year ago

Just so I understand correctly, Does the following code work for you? model_graph.visual_graph.render(format='svg')

If it does, I don't want to make draw_graph API too crowded.

Also, if preferred png (rather than svg) since it sometimes clips the image unexpectedly

turian commented 1 year ago

@mert-kurttutan I guess what I'm really looking for is a way to control the PNG height or width, so that it is not too small.

mert-kurttutan commented 1 year ago

There is the model_graph.resize_graph function whose one argument is scale. scale scales the image size. If you try scale > 1, the image should get bigger. You can try different values to see what value is high enough. At the moment, this is far from ideal essential because of how graphviz sets its image size, which depends many factors, node size, number of nodes etc.

Certainly, one thing that could be done is to use different default values of image size for horizontal setting

turian commented 1 year ago

This is great, thank you! Might I suggest this get added to the docs?

turian commented 1 year ago

There's apparently a lot more possible than I realized with this library :)

mert-kurttutan commented 1 year ago

This is great, thank you! Might I suggest this get added to the docs?

Sure. Any pr or suggestion for format would be valuable. I might change the format of docs. Do you think website dedicated to docs would be beneficial or is readme page enough for docs?

kadirnar commented 1 year ago

@mert-kurttutan

PNG

from torchyolo.predict import YoloHub

model = YoloHub(model_type="yolov5", model_path="yolov5n.pt", device="cuda:0", image_size=640)
model.view_model(file_format="png")
teaser

SVG

from torchyolo.predict import YoloHub

model = YoloHub(model_type="yolov5", model_path="yolov5n.pt", device="cuda:0", image_size=640)
model.view_model(file_format="svg")
teaser
turian commented 1 year ago

@mert-kurttutan I think README is fine, and a lot of people just look at what's on pypi.

On the other hand if you have good docstrings documenting the params, then turning that into documentation automatically could be useful.

kvnptl commented 1 year ago
model_graph.resize_graph(scale=5.0)
model_graph.visual_graph.render(format='svg')

Resizing and saving a graph as SVG is working fine for me.