pytorch可视化工具netron
pytorch可视化工具也不少,但是使用门槛比较高:配置麻烦,使用麻烦,还需要FQ,实力劝退一波。今天发现一个可视化神器----netron,与大家分享一下
这款可视化工具支持多种方式安装(exe是小白最爱),不需要在网络代码中做任何更改。
使用方法:
1.安装netron:https://github.com/lutzroeder/Netron
exe链接可以有:
链接:https://pan.baidu.com/s/1jDEAdEnk1yqjj-ludjVpmQ
提取码:4ors
2.保存网络:这里以LeNet为例
import torch.nn as nn
import torch.nn.functional as F
import torch
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(in_channels=1, out_channels=10, kernel_size=5)
self.conv2 = nn.Conv2d(10, 20, 5)
self.conv3 = nn.Conv2d(20, 40, 3)
self.mp = nn.MaxPool2d(2)
self.mp1 = nn.MaxPool2d(2)
self.fc1 = nn.Linear(2560, 512)
self.fc2 = nn.Linear(512, 10)
def forward(self, x):
in_size = x.size(0)
x = F.relu(self.mp(self.conv1(x)))
x = F.relu(self.mp(self.conv2(x)))
x = F.relu(self.mp1(self.conv3(x)))
x = x.view(in_size, -1)
x = self.fc1(x)
x = self.fc2(x)
return F.log_softmax(x, dim=1)
model = Net().to(device)
torch.save(model, './model_para.pth')
#torch.save(model.state_dict(), './model_para.pth')
3.查看结果
直接打开安装的Netron软件,在软件中直接打开保存的pth文件(其他后缀也可以)

甚至还可以更方便,将pth后缀的文件的默认打开方式改为Netron,直接双击打开。
4.注意保存网络时要保存完整结构,不能只保存参数(如代码中的最后一行注释),否则就会:

这也很好理解原因是吧。
吃水不忘挖井人,最后我们一起瞻仰一下工具作者,来自微软的小哥哥Lutz Roeder:

5.似乎这个工具做的不是很完美,对简单的堆叠构成的网络比较有效(如VGG等)
但是对使用函数构造的,比较复杂的网络就力不从心了。如FasterRCNN:

只能显示到这种程度。那就有点鸡肋了
浙公网安备 33010602011771号