关于深度学习:使用pytorchviz画出好看的Pytorch模型网络结构

3次阅读

共计 839 个字符,预计需要花费 3 分钟才能阅读完成。

在 Pytorch 中能够应用 tensorboardX 画出网络结构图,但总感觉不太好看。pytorchviz 仿佛是一个不错的抉择。

应用办法:

from torchviz import make_dot
from torch.autograd import Variable

net = Model()
x = Variable(torch.randn(3,32,32))

vis_graph = make_dot(net(x), params=dict(net.named_parameters()))
vis_graph.directory = "Net_Structure"   # 设置可视化文件的导出门路
vis_graph.format = "png"       # 如果不加这一句,生成的则是 pdf
vis_graph.view()

如果单纯地 pip install torchviz,会报以下谬误:

graphviz.backend.ExecutableNotFound: failed to execute [‘dot’, ‘-Tpdf’, ‘-O’, ‘Digraph.gv’], make sure the Graphviz executables are on your systems’ PATH

正确的办法:

  1. 下载 package 并解压到本地,例如 D:/test . 我下载的是:这个
  2. Add D:\test\Graphviz\bin to User path
  3. Add D:\test\Graphviz\bin\dot.exe to System Path
  4. 重启计算机

再运行下面的程序后就会发现网络结构图会呈现在一个 pdf 或 png 中


https://zhuanlan.zhihu.com/p/220403674?utm_source=wechat_session https://stackoverflow.com/questions/35064304/runtimeerror-make-sure-the-graphviz-executables-are-on-your-systems-path-aft

正文完
 0