最近论文需要画出网络结构图,这里简单记录一下使用PlotNeuralNet画图的API。
其他工具还有 如何画出漂亮的神经网络图?
各层的定义在tikzeng.py文件中,具体参数可以查看代码。
to_head()、to_cor()、to_begin()这三个函数是必须要调用的。
卷积层详细参数,to_ConvConvRelu()、to_ConvRes()、to_ConvSoftMax()同理,唯二不同的是因为比普通卷积层多了一层激活函数,to_ConvConvRelu()等函数的n_filer和width参数,以元组形式同时包括卷积层和激活层的尺寸,例如n_filer=(64,64), width=(2,2)
to_Conv(name,s_filer=256,n_filer=64,offset=“(0,0,0)”,to=“(0,0,0)”,width=1,height=40, depth=40, caption=" ")
name–名称(显示在当前层的下方)
s_filer–卷积层图像尺寸 # 指卷积层结构的参数,并非制图时的尺寸
n_filer–卷积层图像深度(通道数) # 指卷积层结构的参数,并非制图时的尺寸
offset–与前一层分别在x,y,z方向的距离
to–在x,y,z方向的坐标,
width–制图时的厚度
height、depth–制图时的长宽
width、height、depth指在制图时,卷积层的尺寸
caption–备注信息
池化层详细参数
to_Pool(name,offset=“(0,0,0)”,to=“(0,0,0)”,width=1,height=32,depth=32,opacity=0.5,caption=" ")
部分参数与卷积层相同
opacity–透明度,0-1之间
to=“(conv1-east)”–在con1层的东侧
import sys
sys.path.append('../')
from pycore.tikzeng import *
from pycore.blocks import *
arch = [
# 以VGG-F网络为例
# conv1
to_ConvConvRelu( name='conv1', s_filer=55, n_filer=(96,96), offset="(0,0,0)", to="(0,0,0)", width=(2,2), height=40, depth=40, caption='Conv1' ),
to_Pool(name="pool1", offset="(0,0,0)", to="(conv1-east)", width=1, height=32, depth=32, opacity=0.5),
#conv2
to_ConvConvRelu( name='conv2', s_filer=27, n_filer=(256,256), offset="(1,0,0)", to="(pool1-east)", width=(3,3), height=35, depth=35, caption='Conv2' ),
to_connection( "pool1", "conv2"),
to_Pool(name="pool2", offset="(0,0,0)", to="(conv2-east)", width=1, height=30, depth=30, opacity=0.5),
# conv3
to_ConvConvRelu( name='conv3', s_filer=13, n_filer=(384,384), offset="(1,0,0)", to="(pool2-east)", width=(5,5), height=30, depth=30, caption='Conv3' ),
to_connection( "pool2", "conv3"),
# conv4
to_ConvConvRelu( name='conv4', s_filer=13, n_filer=(384,384), offset="(1,0,0)", to="(conv3-east)", width=(5,5), height=25, depth=25, caption='Conv4' ),
to_connection( "conv3", "conv4"),
# conv5
to_ConvConvRelu( name='conv5', s_filer=13, n_filer=(256,256), offset="(1,0,0)", to="(conv4-east)", width=(4,4), height=25, depth=25, caption='Conv5' ),
to_Pool(name="pool3", offset="(0,0,0)", to="(conv5-east)", width=1, height=20, depth=20, opacity=0.5),
to_connection( "conv4", "conv5"),
# fc1
to_SoftMax(name='fc1', s_filer=4096, offset="(4,0,0)", to="(pool3-east)", width=1.5, height=1.5, depth=100, opacity=0.8, caption='FC1'),
to_connection( "pool3", "fc1"),
# fc2
to_SoftMax(name='fc2', s_filer=4096, offset="(1.5,0,0)", to="(fc1-east)", width=1.5, height=1.5, depth=100, opacity=0.8, caption='FC2'),
to_connection( "fc1", "fc2"),
# fc1
to_SoftMax(name='fc3', s_filer=1000, offset="(1.5,0,0)", to="(fc2-east)", width=1.5, height=1.5, depth=70, opacity=0.8, caption='FC3'),
to_connection( "fc2", "fc3"),
to_end()
]
def main():
namefile = str(sys.argv[0]).split('.')[0]
to_generate(arch, namefile + '.tex' )
if __name__ == '__main__':
main()
更详细信息可查看:
[1] 面向Python的PlotNeuralNet教程
[2] 使用PlotNeuralNet绘制深度学习网络图