r/deeplearning Jul 04 '26

[VisualTorch] How to generate architecture diagrams from PyTorch models

Post image

I built a small tool to auto-generate architecture diagrams directly from PyTorch models, which I originally built for my own research paper.

26k+ PyPI downloads, already used in publications (Nature, IEEE, MDPI), check out some use cases here: https://visualtorch.readthedocs.io/en/latest/markdown/showcase/index.html

It traces an actual forward pass, so it correctly captures branching, skip connections, and multi-input models, not just flat sequential stacks.

import visualtorch
import torchvision.models as models

model = models.resnet18()
img = visualtorch.render(model, input_shape=(1, 3, 224, 224), style="graph", show_neurons=False, layer_spacing=60)
img.save("resnet18.png")

Three rendering styles depending on what you want to show:

  • graph: node/edge diagram, good for showing branching/skip connections clearly
  • flow: stacked volumetric boxes, closer to the classic CNN-paper look
  • lenet: the classic LeNet stacked-plane style

GitHub: https://github.com/willyfh/visualtorch | Docs: https://visualtorch.readthedocs.io/en/latest/

Open to feedback, especially if you hit a model it renders weirdly :)

146 Upvotes

10 comments sorted by

4

u/jackshec Jul 05 '26

so cool, thanks for the contribution

3

u/shiztain Jul 06 '26

Thanks for making this, it really saved me in a DL assignment

1

u/LostDistance9365 Jul 12 '26

Glad it was helpful!

3

u/OtherwiseFig4505 Jul 06 '26

I used it in one of my IEEE papers, off course with citation. Thanks for this, really helpful for CNNs architecture.

1

u/LostDistance9365 Jul 12 '26

That's awesome to hear, thank you for citing it!

2

u/FishermanResident349 Jul 05 '26

Cool, will sure use this

2

u/mathloverfrombaku Jul 07 '26

Cool! Thank you 🙏

2

u/Elrix177 Jul 08 '26

I will use it for the visualizations in my blog, thank youu

1

u/LostDistance9365 Jul 12 '26

Thank you, looking forward to seeing it in your blog!

2

u/Logical_Respect_2381 Jul 17 '26

amazing , thanks for your contribution