先解决下keras可视化安装graphviz的问题:

注意安装顺序:

sudo pip3 install graphviz  # python包

sudo apt-get install graphviz   # 软件本身

sudo pip3 install pydot

sudo pip3 install pydot-ng  # 版本兼容需要,可选

 

1.  使用pytorchviz进行pytorch执行过程的可视化

sudo pip3 install git   # 安装git
sudo  pip3 install git+https://github.com/szagoruyko/pytorchviz   # github上的包

demo:

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)

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

Pytorch之可视化

 

详见: https://github.com/szagoruyko/pytorchviz