netron对神经网络可视化
netron对神经网络可视化
1 安装netron
在环境下安装,
pip insall netron
2 测试
用以下代码测试
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.onnx
import netron
class ForwardNet(nn.Module):
def __init__(self):
super(ForwardNet, self).__init__()
self.block1 = nn.Sequential(
nn.Conv2d(64, 64, 3, padding=1, bias=False),
nn.BatchNorm2d(64),
nn.ReLU(inplace=True),
nn.Conv2d(64, 32, 1, bias=False),
nn.BatchNorm2d(32),
nn.ReLU(inplace=True),
nn.Conv2d(32, 64, 3, padding=1, bias=False),
nn.BatchNorm2d(64)
)
self.conv1 = nn.Conv2d(3, 64, 3, padding=1, bias=False)
self.output = nn.Sequential(
nn.Conv2d(64, 1, 3, padding=1, bias=True),
nn.Sigmoid()
)
def forward(self, x):
x = self.conv1(x)
identity = x
x = F.relu(self.block1(x) + identity)
x = self.output(x)
return x
input = torch.rand(1, 3, 416, 416)
model = ForwardNet()
output = model(input)
onnx_path = "netForwatch.onnx"
torch.onnx.export(model, input, onnx_path)
netron.start(onnx_path)
3 解读
效果如下,可以点开查看具体的参数,但是不是每一维的输入都是看见,还是要自己计算。
上面的代码是先调用self.conv1,他的输入深度为3,输出深度为64,kernel为3,也就是用了64个3通道3*3的卷积核,pad=1,没有bias,所以输出特征图的大小为
(
i
m
g
s
i
z
e
+
2
∗
p
a
d
i
n
g
−
(
k
e
r
n
e
l
s
i
z
e
−
1
)
)
=
(
416
+
1
∗
2
−
2
)
=
416
(imgsize+2*pading-(kernelsize-1)) = (416+1*2-2)=416
(imgsize+2∗pading−(kernelsize−1))=(416+1∗2−2)=416

参考:
神经网络可视化工具:https://zhuanlan.zhihu.com/p/147462170
更多推荐
所有评论(0)