Pytorch 可视化笔记1:pytorchviz

(1)首先安装graphviz

(2)命令行安装pytorchviz

pip install git+https://github.com/szagoruyko/pytorchviz

(3)示例代码

import torch
import torch.nn as nn
import torchviz
from torch.autograd import Variable

model = nn.Sequential()
model.add_module('W0',nn.Linear(8,16))
model.add_module('tanh', nn.Tanh())
model.add_module('W1',nn.Linear(16,1))

x = Variable(torch.randn(1,8))
y = model(x)

torchviz.make_dot(y.mean(), params=dict(model.named_parameters()))

Pytorch 可视化笔记1:pytorchviz_第1张图片

Pytorch 可视化笔记1:pytorchviz_第2张图片

 

参考文献:

https://blog.csdn.net/nima1994/article/details/83008349

你可能感兴趣的:(深度学习)