pytorch中模型结构图的可视化

本文介绍了三种PyTorch模型结构的可视化方法:1) 使用torchsummary输出模型概览;2) 利用torchviz创建模型结构图;3) 探讨了其他如tensorwatch和netron等可视化工具的使用。

1. 使用summary输出模型结构

  • 安装torchsummary:pip install torchsummary
  • 使用:
    from torchsummary import summary
    summary(your_model, input_size=(channels, H, W), device='cpu')
  • 参考文章:使用torchsummary打印torch每层形状:https://www.cnblogs.com/yyf2019/p/11674266.html

2. 使用 torchviz 输出模型结构图

  • 安装Graphviz:sudo apt-get install graphviz
  • 在虚拟环境下安装: pip install graphvizpip install torchviz
  • 使用
from torchviz import make_dot

# ...... 

x = Variable(torch.randn(1, 3, 32, 32))
vis_graph = make_dot(model(x)) # 或者 vis_graph = make_dot(model(x), params=dict(model.named_parameters()))
vis_graph.view('VGGNet.gv')  # 保存的文件名,会自动生成 xxx.gv 和 xxx.pdf

3. 其他的可视化方法:

  • 使用微软的tensorwatch (只能在jupyter notebook中使用,个人最喜欢这种方式)

  • 使用netron可视化工具(.pt 或者是 .pth 文件)

  • 参考博客:

pytorch 网络结构可视化方法汇总(三种实现方法详解)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值