PlotNeuralNet 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}
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
根据引用\[1\]中提到的信息,使用pycore/tikzeng.py中的函数plotneuralnet可以绘制神经网络结构图。然而,引用中也提到了一些限制,例如tikzeng.py中的to_skip函数只能从结构的上方进行连接,无法实现从侧面引出的箭头。因此,如果要画出类似于resnet50这样的网络结构图,可能需要对代码进行修改。 另外,引用\[3\]中提到,plotneuralnet工具是对latex的绘图脚本进行封装,将常见的网络结构图形封装成python函数,以简化绘制过程。然而,作者提供的示例中只有.tex版本的网络结构图,没有提供相应的python脚本。因此,如果要使用plotneuralnet绘制resnet50的网络结构图,可能需要自己花一些时间来摸索和尝试。 综上所述,要使用plotneuralnet绘制resnet50的网络结构图,可能需要对代码进行修改,并且需要自己摸索和尝试。 #### 引用[.reference_title] - *1* *3* [使用PlotNeuralNet绘制自己的网络结构图](https://blog.csdn.net/Barry_123/article/details/122311965)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [【Tensorflow】【PlotNeuralNet】画神经网络图的(两种方法)小结](https://blog.csdn.net/weixin_39190382/article/details/106967831)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

书文的学习记录本

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值