• PlotNeuralNet resnet34和resnet18绘图


    文章目录


    PlotNeuralNet网络

    在这里插入图片描述可以发现,resnet34和resnet18只有块的数量不一样,经过简单的修改即可得到

    resnet18

    参考链接

    \documentclass[border=12pt, multi, tikz]{standalone}
    \usepackage[fontsize=14pt]{fontsize}
    \usepackage{import}
    \subimport{./layers/}{init}
    \usetikzlibrary{positioning}
    \usetikzlibrary{3d} %for including external image 
    
    \def\ConvColor{rgb:yellow,5;red,2.5;white,5}
    \def\ConvReluColor{rgb:yellow,5;red,5}
    \def\bnColor{rgb:yellow,5;red,5}
    \def\PoolColor{rgb:red,1;black,0}
    \def\UnpoolColor{rgb:blue,2;green,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}
    \def\SumColor{rgb:blue,5;green,15}
    \def\LayerColor{rgb:black,1}
    
    \newcommand{\copymidarrow}{\tikz \draw[-Stealth,line width =1mm,draw={rgb:blue,4;red,1;green,1;black,3}] (-0.3,0) -- ++(0.3,0);}
    
    
    \begin{document}
    \noindent
    \begin{tikzpicture}
    	\tikzstyle{connection}=[ultra thick,every node/.style={sloped,allow upside down},draw=\edgecolor,opacity=0.7]
    	\tikzstyle{copyconnection}=[ultra thick,every node/.style={sloped,allow upside down},draw={rgb:blue,4;red,1;green,1;black,3},opacity=0.7]
    
    	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    	%% Draw Encoder
    	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    	\path (-4,0,0);
    	% input
    	\pic[shift={(0,0,0)}] at (0,0,0) {
    		Box={
    				name=input,
    				caption=Input,
    				xlabel= 3,
    				ylabel=224,
    				zlabel= \qquad 224,
    				fill=\ConvColor,
    				height=100,
    				width=0.1,
    				depth=100
    			}
    	};
    	% conv1
    	\pic[shift={(1.5,0,0)}] at (input-east) {
    		RightBandedBox={
    				name= conv1,
    				caption=Conv1,
    				xlabel={{"64",""}},
    				ylabel=112,
    				zlabel= \qquad 112,
    				fill=\ConvColor,
    				bandfill=\ConvReluColor,
    				height=50,
    				width=2.1,
    				depth=50
    			}
    	};
    	% MaxPool2d
    	\pic[shift={(1,0,0)}] at (conv1-east) {
    		RightBandedBox={
    			name= MaxPool,
    			xlabel={{"64",""}},
    			ylabel=112,
    			fill=\PoolColor,
    			height=50,
    			width=2.1,
    			depth=50
    		}
    	};
    
    
    
    	% layer1
    	% conv1_1
    	\pic[shift={(3,0,0)}] at (MaxPool-east) {
    		RightBandedBox={
    				name= conv1_1,
    				xlabel={{"64",""}},
    				ylabel= 112,
    				fill=\ConvColor,
    				bandfill=\ConvReluColor,
    				height=50,
    				width=2.1,
    				depth=50
    			}
    	};
    	% conv1_2
    	\pic[shift={(0,0,0)}] at (conv1_1-east) {
    		RightBandedBox={
    				name= conv1_2,
    				xlabel={{"\quad 64",""}},
    				zlabel= \qquad 112,
    				fill=\ConvColor,
    				bandfill=\ConvReluColor,
    				height=50,
    				width=2.1,
    				depth=50
    			}
    	};
    	% add1_1
    	\pic[shift={(1,0,0)}] at (conv1_2-east) {
    		Ball={
    				name=add1_1,
    				fill=\SumColor,
    				opacity=0.6,
    				radius=2,
    				logo=\(+\)
    			}
    	};
    \pic[shift={(-0.2,0,0)}] at (conv1_1-west) {Box={name=env,caption=\textbf{\large{$\times$ 2}},%
    		xlabel={{"","dummy"}},fill=,opacity=0.1,height=60,width={10},depth=60}};
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    	\pic[shift={(3,0,0)}] at (conv1_2-east) {
    		RightBandedBox={
    			name= conv2_1,
    			xlabel={{"128",""}},
    			ylabel= 56,
    			fill=\ConvColor,
    			bandfill=\ConvReluColor,
    			height=25,
    			width=4.2,
    			depth=25
    		}
    	};
    	% conv2_2
    	\pic[shift={(0,0,0)}] at (conv2_1-east) {
    		RightBandedBox={
    			name= conv2_2,
    			xlabel={{"128",""}},
    			zlabel= \qquad 56,
    			fill=\ConvColor,
    			bandfill=\ConvReluColor,
    			height=25,
    			width=4.2,
    			depth=25
    		}
    	};
    
    	% add1_2
    	\pic[shift={(1,0,0)}] at (conv2_2-east) {
    		Ball={
    			name=add1_2,
    			fill=\SumColor,
    			opacity=0.6,
    			radius=2,
    			logo=\(+\)
    		}
    	};
    \pic[shift={(-0.4,0,0)}] at (conv2_1-west) {Box={name=env,caption=\textbf{\large{$\times$ 2}},%
    		xlabel={{"","dummy"}},fill=,opacity=0.1,height=30,width={20},depth=30}};
    
    	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    	% conv3_1
    	\pic[shift={(3,0,0)}] at (conv2_2-east) {
    		RightBandedBox={
    			name= conv3_1,
    			xlabel={{"256",""}},
    			ylabel= 28,
    			fill=\ConvColor,
    			bandfill=\ConvReluColor,
    			height=12.5,
    			width=8.4,
    			depth=12.5
    		}
    	};
    	% conv3_2
    	\pic[shift={(0,0,0)}] at (conv3_1-east) {
    		RightBandedBox={
    		name= conv3_2,
    		xlabel={{"256",""}},
    		zlabel= 28,
    		fill=\ConvColor,
    		bandfill=\ConvReluColor,
    		height=12.5,
    		width=8.4,
    		depth=12.5
    		}
    	};
    	
    	% add1_3
    	\pic[shift={(1,0,0)}] at (conv3_2-east) {
    		Ball={
    			name=add1_3,
    			fill=\SumColor,
    			opacity=0.6,
    			radius=2,
    			logo=\(+\)
    		}
    	};
    \pic[shift={(-0.6,0,0)}] at (conv3_1-west) {Box={name=env,caption=\textbf{\large{$\times$ 2}},%
    		xlabel={{"","dummy"}},fill=,opacity=0.1,height=20,width={30},depth=20}};
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    	% conv4_1
    	\pic[shift={(3,0,0)}] at (conv3_2-east) {
    		RightBandedBox={
    			name= conv4_1,
    			xlabel={{"512",""}},
    			ylabel= 14,
    			fill=\ConvColor,
    			bandfill=\ConvReluColor,
    			height=6.25,
    			width=16.8,
    			depth=6.25
    		}
    	};
    	% conv4_2
    	\pic[shift={(0,0,0)}] at (conv4_1-east) {
    		RightBandedBox={
    			name= conv4_2,
    			xlabel={{"512",""}},
    			ylabel= 14,
    			fill=\ConvColor,
    			bandfill=\ConvReluColor,
    			height=6.25,
    			width=16.8,
    			depth=6.25
    		}
    	};
    	
    	% add1_4
    	\pic[shift={(1,0,0)}] at (conv4_2-east) {
    		Ball={
    			name=add1_4,
    			fill=\SumColor,
    			opacity=0.6,
    			radius=2,
    			logo= \(+\)
    		}
    	};
    \pic[shift={(-0.8,0,0)}] at (conv4_1-west) {Box={name=env,caption=\textbf{\large{$\times$ 2}},%
    		xlabel={{"","dummy"}},fill=,opacity=0.1,height=15,width={48},depth=15}};
    
    	% avgpool
    \pic[shift={(3,0,0)}] at (add1_4-east) {
    	Box={
    		name=avgpool,
    		caption= \\ avgpool,
    		xlabel={{"1",""}},
    		ylabel=1,
    		zlabel=\qquad 512,
    		fill=\PoolColor,
    		height=2,
    		width=2,
    		depth=150
    	}
    };
    
    
    	% fullconnection
    	\pic[shift={(2,0,0)}] at (avgpool-east) {
    		RightBandedBox={
    				name=fc,
    				caption=\makebox[0pt]{
    					 \shortstack[c]{\\ full \, connection\\softmax}},
    				xlabel={{"1",""}},
    				zlabel=\qquad 7,
    				fill=\FcColor,
    				bandfill=\SoftmaxColor,
    				height=2,
    				width=2,
    				depth=20
    			}
    	};
    
    	% connections
    	\draw [connection]  		(input-east)			-- 	node {\midarrow} 	(conv1-west);
    	\draw [connection]  		(conv1-east)			-- 	node {\midarrow} 	(MaxPool-west);
    	\draw [connection] (MaxPool-east) -- node {\midarrow} (conv1_1-west);
    
    
    	% connections shortcut
    	% conv1 to add1_1
    	\path (MaxPool-east) -- (conv1_1-west) coordinate[pos=0.5] (pool_conv1_1);
    	\path (pool_conv1_1) ++ (0,5,0) coordinate (pool_conv1_1_above);
    	\path (add1_1-north) ++ (0,5,0) coordinate (add1_1-north-above);
    	
    	\draw [connection] (pool_conv1_1) -- node {\midarrow} (pool_conv1_1_above|-add1_1-north-above) -- node {\midarrow} (add1_1-north-above) -- node {\midarrow} (add1_1-north);
    	\draw [connection] (conv1_2-east) -- (add1_1-west);
    	\draw [connection] (add1_1-east) -- node {\midarrow} (conv2_1-west);
    	
    	%
    	\path (conv1_2-east) -- (conv2_1-west) coordinate[pos=0.65] (add_conv_1);
    	\path (add_conv_1) ++ (0,5,0) coordinate (add_conv_1-above);
    	\path (add1_2-north) ++ (0,5,0) coordinate (add1_2-north-above);
    	\draw [connection] (add_conv_1) -- node {\midarrow} (add_conv_1-above|-add1_2-north-above) -- node {\midarrow} (add1_2-north-above) -- node {\midarrow} (add1_2-north);
    	\draw [connection] (conv2_2-east) -- (add1_2-west);
    	\draw [connection] (add1_2-east) -- node {\midarrow} (conv3_1-west);
    	%%%%%%%%%%%%%%
    	\path (conv2_2-east) -- (conv3_1-west) coordinate[pos=0.75] (add_conv_2);
    	\path (add_conv_2) ++ (0,5,0) coordinate (add_conv_2-above);
    	\path (add1_3-north) ++ (0,5,0) coordinate (add1_3-north-above);
    	\draw [connection] (add_conv_2) -- node {\midarrow} (add_conv_2-above|-add1_3-north-above) -- node {\midarrow} (add1_3-north-above) -- node {\midarrow} (add1_3-north);
    	\draw [connection] (conv3_2-east) -- (add1_3-west);
    	\draw [connection] (add1_3-east) -- node {\midarrow} (conv4_1-west);
    	%%%%%%%%%%%%%%%
    	\path (conv3_2-east) -- (conv4_1-west) coordinate[pos=0.75] (add_conv_3);
    	\path (add_conv_3) ++ (0,5,0) coordinate (add_conv_3-above);
    	\path (add1_4-north) ++ (0,5,0) coordinate (add1_4-north-above);
    	\draw [connection] (add_conv_3) -- node {\midarrow} (add_conv_3-above|-add1_4-north-above) -- node {\midarrow} (add1_4-north-above) -- node {\midarrow} (add1_4-north);
    	\draw [connection] (conv4_2-east) -- (add1_4-west);
    	%\draw [connection] (add1_4-east) -- node {\midarrow} (conv4_1-west);
    \draw [connection](add1_4-east) -- node {\midarrow}(avgpool-west);
    \draw [connection](avgpool-east) -- node {\midarrow}(fc-west);
    	% pool & fullconnection
    \draw	[densely dashed]  (avgpool-nearnortheast)    	--  									(fc-nearnorthwest);
    \draw	[densely dashed]  (avgpool-nearsoutheast)    	--  									(fc-nearsouthwest);
    \draw	[densely dashed]  (avgpool-farnortheast)    	--  									(fc-farnorthwest);
    \draw	[densely dashed]  (avgpool-farsoutheast)    	--  									(fc-farsouthwest);
    %
    	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \end{tikzpicture}
    \end{document}
    
    • 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
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
  • 相关阅读:
    Cesium 地球(1)-概览
    ArcObjects SDK开发 012 PageLayout和Page
    猿创征文|我Java开发那些年陪我成长的工具清单
    八大排序算法(C语言版)之插入排序
    程序设计与软件设计模式
    mysql连接不上可能的原因:防火墙放行mysql的3306端口 全库复制:data目录替换即可 mysql查看版本
    Spring源码解析——Spring事务是怎么通过AOP实现的?
    (附源码)ssm在线学习网站 毕业设计 080833
    C语言自定义类型
    HummerRisk V0.5.1 发布:新增对象存储、优化K8s 资源态势和资源拓扑等
  • 原文地址:https://blog.csdn.net/qq_43935969/article/details/133151907