平常怎样在论文里画神经网络结构图是个头疼的问题。一直以来 PowerPoint 最受欢迎,但有没有专门的针对画神经网络结构图的工具呢?如果我要是用 Letex 怎么办,可以直接画吗?
PlotNeuralNet 就是这样一个工具,它支持 Latex,并且提供一个 Python 接口。既可以用 Latex 实现,也可以用简单的几句 Python 定义网络结构后自动生成。
图像示例
下面我们看一些例子:
FCN-8
VGG-16
Holistically-Nested Edge Detection
Python 示例
下面是怎样用 Python 定义一个简单网络结构的示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | mkdir my_project cd my_project vim my_arch.py import sys sys.path.append('../') from pycore.tikzeng import * # defined your arch arch = [ to_head( '..' ), to_cor(), to_begin(), to_Conv("conv1", 512, 64, offset="(0,0,0)", to="(0,0,0)", height=64, depth=64, width=2 ), to_Pool("pool1", offset="(0,0,0)", to="(conv1-east)"), to_Conv("conv2", 128, 64, offset="(1,0,0)", to="(pool1-east)", height=32, depth=32, width=2 ), to_connection( "pool1", "conv2"), to_Pool("pool2", offset="(0,0,0)", to="(conv2-east)", height=28, depth=28, width=1), to_SoftMax("soft1", 10 ,"(3,0,0)", "(pool1-east)", caption="SOFT" ), to_connection("pool2", "soft1"), to_end() ] def main(): namefile = str(sys.argv[0]).split('.')[0] to_generate(arch, namefile + '.tex' ) if __name__ == '__main__': main() bash ../tikzmake.sh my_arch |
Latex 示例
下面是 Latex 定义 VGG-16 的代码示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | \documentclass[border=15pt, multi, tikz]{standalone} %\usepackage{blocks} \usepackage{import} \subimport{../../layers/}{init} \usetikzlibrary{positioning} \def\ConvColor{rgb:yellow,5;red,2.5;white,5} \def\ConvReluColor{rgb:yellow,5;red,5;white,5} \def\PoolColor{rgb:red,1;black,0.3} \def\FcColor{rgb:blue,5;red,2.5;white,5} \def\FcReluColor{rgb:blue,5;red,5;white,4} \def\SoftmaxColor{rgb:magenta,5;black,7} \begin{document} \begin{tikzpicture} \tikzstyle{connection}=[ultra thick,every node/.style={sloped,allow upside down},draw=\edgecolor,opacity=0.7] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Draw Layer Blocks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % conv1_1,conv1_2 \pic[shift={(0,0,0)}] at (0,0,0) {RightBandedBox={name=cr1,caption=conv1,% xlabel={{"64","64"}},ylabel=224,zlabel=224,fill=\ConvColor,bandfill=\ConvReluColor,% height=40,width={2,2},depth=40}}; %pool1 \pic[shift={(0,0,0)}] at (cr1-east) {Box={name=p1,% fill=\PoolColor,opacity=0.5,height=35,width=1,depth=35}}; %%%%%%%%%% % conv2_1,conv2_2 \pic[shift={(2,0,0)}] at (p1-east) {RightBandedBox={name=cr2,caption=conv2,% xlabel={{"64","64"}},zlabel=112,fill=\ConvColor,bandfill=\ConvReluColor,% height=35,width={3,3},depth=35}}; %pool2 \pic[shift={(0,0,0)}] at (cr2-east) {Box={name=p2,% fill=\PoolColor,opacity=0.5,height=30,width=1,depth=30}}; %%%%%%%%%% % conv3_1,conv3_2 \pic[shift={(2,0,0)}] at (p2-east) {RightBandedBox={name=cr3,caption=conv3,% xlabel={{"256","256","256"}},zlabel=56,fill=\ConvColor,bandfill=\ConvReluColor,% height=30,width={4,4,4},depth=30}}; %pool3 \pic[shift={(0,0,0)}] at (cr3-east) {Box={name=p3,% fill=\PoolColor,opacity=0.5,height=23,width=1,depth=23}}; %%%%%%%%%% % conv4_1,conv4_2,conv4_3 \pic[shift={(1.8,0,0)}] at (p3-east) {RightBandedBox={name=cr4,caption=conv4,% xlabel={{"512","512","512"}},zlabel=28,fill=\ConvColor,bandfill=\ConvReluColor,% height=23,width={7,7,7},depth=23}}; %pool4 \pic[shift={(0,0,0)}] at (cr4-east) {Box={name=p4,% fill=\PoolColor,opacity=0.5,height=15,width=1,depth=15}}; %%%%%%%%%% % conv5_1,conv5_2,conv5_3 \pic[shift={(1.5,0,0)}] at (p4-east) {RightBandedBox={name=cr5,caption=conv5,% xlabel={{"512","512","512"}},zlabel=14,fill=\ConvColor,bandfill=\ConvReluColor,% height=15,width={7,7,7},depth=15}}; %pool5 \pic[shift={(0,0,0)}] at (cr5-east) {Box={name=p5,% fill=\PoolColor,opacity=0.5,height=10,width=1,depth=10}}; %%%%%%%%%% % fc6 \pic[shift={(3,0,0)}] at (p5-east) {RightBandedBox={name=fc6,caption=fc6,% xlabel={{"1",""}},zlabel=4096,fill=\FcColor,bandfill=\FcReluColor,% height=3,width=3,depth=100}}; %%%%%%%%%% % fc7 \pic[shift={(2,0,0)}] at (fc6-east) {RightBandedBox={name=fc7,caption=fc7,% xlabel={{"1","dummy"}},zlabel=4096,fill=\FcColor,bandfill=\FcReluColor,% height=3,width=3,depth=100}}; %%%%%%%%%% % fc8 \pic[shift={(1.5,0,0)}] at (fc7-east) {RightBandedBox={name=fc8,caption=fc8+softmax,% xlabel={{"1","dummy"}},fill=\FcColor,bandfill=\FcReluColor,% height=3,width=3,depth=25}}; %%%%%%%%%% % softmax \pic[shift={(0,0,0)}] at (fc8-east) {Box={name=softmax,% xlabel={{"","dummy"}},zlabel=K,opacity=0.8,fill=\SoftmaxColor,% height=3,width=1.5,depth=25}}; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Draw Arrow Connections %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \draw [connection] (p1-east) -- node {\midarrow} (cr2-west); \draw [connection] (p2-east) -- node {\midarrow} (cr3-west); \draw [connection] (p3-east) -- node {\midarrow} (cr4-west); \draw [connection] (p4-east) -- node {\midarrow} (cr5-west); \draw [connection] (p5-east) -- node {\midarrow} (fc6-west); \draw [connection] (fc6-east) -- node {\midarrow} (fc7-west); \draw [connection] (fc7-east) -- node {\midarrow} (fc8-west); \draw [connection] (softmax-east) -- node {\midarrow} ++(1.5,0,0); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Draw Dotted Edges %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \draw[densely dashed] (fc6-west)++(0, 1.5*.2, 1.5*.2) coordinate(a) -- (p5-nearnortheast) (fc6-west)++(0,-1.5*.2, 1.5*.2) coordinate(b) -- (p5-nearsoutheast) (fc6-west)++(0,-1.5*.2,-1.5*.2) coordinate(c) -- (p5-farsoutheast) (fc6-west)++(0, 1.5*.2,-1.5*.2) coordinate(d) -- (p5-farnortheast) (a)--(b)--(c)--(d) ; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \end{tikzpicture} \end{document} |
项目 Github 地址:https://github.com/HarisIqbal88/PlotNeuralNet
本站微信群、QQ群(三群号 726282629):