在Pytorch中能够应用tensorboardX画出网络结构图,但总感觉不太好看。pytorchviz 仿佛是一个不错的抉择。
应用办法:
from torchviz import make_dotfrom torch.autograd import Variablenet = 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" # 如果不加这一句,生成的则是pdfvis_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
正确的办法:
- 下载package并解压到本地,例如
D:/test
. 我下载的是:这个 - Add
D:\test\Graphviz\bin
to User path - Add
D:\test\Graphviz\bin\dot.exe
to System Path - 重启计算机
再运行下面的程序后就会发现网络结构图会呈现在一个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