\documentclass[border=15pt, multi, tikz]{standalone}
\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;white,5}
\def\PoolColor{rgb:red,1;black,0.3}
\def\DcnvColor{rgb:blue,5;green,2.5;white,5}
\def\SoftmaxColor{rgb:magenta,5;black,7}
\def\SumColor{rgb:blue,5;green,15}
\tikzstyle{copyconnection}=[ultra thick,every node/.style={sloped,allow upside down},draw={rgb:blue,4;red,1;green,1;black,3},opacity=0.7]
\newcommand{\copymidarrow}{\tikz \draw[-Stealth,line width =0.8mm,draw={rgb:blue,4;red,1;green,1;black,3}] (-0.3,0) -- ++(0.3,0);}
\begin{document}
\begin{tikzpicture}
\tikzstyle{connection}=[ultra thick,every node/.style={sloped,allow upside down},draw=\edgecolor,opacity=0.7]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Draw Layer Blocks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\node[canvas is zy plane at x=0] (temp) at (-3,0,0) {\includegraphics[width=8cm,height=8cm]{cats.png}};
% conv1_1,conv1_2,%pool1
\pic[shift={(0,0,0)}] at (0,0,0) {RightBandedBox={name=cr1,caption=Conv,%
,fill=\ConvColor,bandfill=\ConvReluColor,%
height=40,width={2},depth=40}};
\pic[shift={(4,0,0)}] at (cr1-east) {RightBandedBox={name=cr110,caption=Conv,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=40,width={2},depth=40}};
\pic[shift={(4,0,0)}] at (cr110-east) {RightBandedBox={name=cr11,caption=Conv,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=40,width={2},depth=40}};
\pic[shift={(4,0,0)}] at (cr11-east) {RightBandedBox={name=cr112,caption=Conv,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=40,width={2},depth=40}};
% conv3_1,conv3_2,pool3
\pic[shift={(3,0,0)}] at (cr112-east) {RightBandedBox={name=cr2,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={2},depth=6}};
\pic[shift={(0,0,0)}] at (cr2-east) {RightBandedBox={name=cr21,caption=Block1,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=18,width={2},depth=18}};
\pic[shift={(0,0,0)}] at (cr21-east) {RightBandedBox={name=cr22,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={8},depth=6}};
\pic[shift={(0,0,0)}] at (cr22-east) {Box={name=p2,caption=MaxPooling,%
fill=\PoolColor,opacity=0.5,height=12,width=8,depth=12}};
\pic[shift={(3,0,0)}] at (p2-east) {RightBandedBox={name=cr3,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={2},depth=6}};
\pic[shift={(0,0,0)}] at (cr3-east) {RightBandedBox={name=cr31,caption=Block1,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=18,width={2},depth=18}};
\pic[shift={(0,0,0)}] at (cr31-east) {RightBandedBox={name=cr32,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={8},depth=6}};
\pic[shift={(0,0,0)}] at (cr32-east) {Box={name=p3,caption=MaxPooling,%
fill=\PoolColor,opacity=0.5,height=12,width=8,depth=12}};
\pic[shift={(6,2.5,0)}] at (p3-east) {RightBandedBox={name=cr4,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={4},depth=6}};
\pic[shift={(0,0,0)}] at (cr4-east) {RightBandedBox={name=cr41,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={4},depth=18}};
\pic[shift={(0,0,0)}] at (cr41-east) {RightBandedBox={name=cr42,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=18,width={6},depth=6}};
\pic[shift={(6,-2.6,0)}] at (p3-east) {RightBandedBox={name=cr5,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={4},depth=6}};
\pic[shift={(0,0,0)}] at (cr5-east) {RightBandedBox={name=cr51,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=18,width={4},depth=18}};
\pic[shift={(0,0,0)}] at (cr51-east) {RightBandedBox={name=cr52,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=18,width={6},depth=18}};
\pic[shift={(7,5.8,0)}] at (p3-east) {RightBandedBox={name=cr6,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={6},depth=6}};
\pic[shift={(6,-7,0)}] at (p3-east) {RightBandedBox={name=cr7,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={6},depth=6}};
\pic[shift={(0,0,0)}] at (cr7-east) {Box={name=p4,caption=Block2,%
fill=\PoolColor,opacity=0.5,height=12,width=6,depth=12}};
\pic[shift={(12,0,0)}] at (p3-east) {Ball={name=elt1,%
fill=\SumColor,opacity=0.6,%
radius=2.5,logo=$+$}};
\pic[shift={(10,0,0)}] at (cr41-east) {RightBandedBox={name=cr8,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={4},depth=6}};
\pic[shift={(0,0,0)}] at (cr8-east) {RightBandedBox={name=cr81,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={4},depth=18}};
\pic[shift={(0,0,0)}] at (cr81-east) {RightBandedBox={name=cr82,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=18,width={6},depth=6}};
\pic[shift={(10,0,0)}] at (cr51-east) {RightBandedBox={name=cr9,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={4},depth=6}};
\pic[shift={(0,0,0)}] at (cr9-east) {RightBandedBox={name=cr91,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=18,width={4},depth=18}};
\pic[shift={(0,0,0)}] at (cr91-east) {RightBandedBox={name=cr92,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=18,width={6},depth=18}};
\pic[shift={(10.3,0,0)}] at (cr6-east) {RightBandedBox={name=cr10,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={6},depth=6}};
\pic[shift={(9,0,0)}] at (p4-east) {RightBandedBox={name=cr12,%
fill=\ConvColor,bandfill=\ConvReluColor,%
height=6,width={6},depth=6}};
\pic[shift={(0,0,0)}] at (cr12-east) {Box={name=p5,caption=Block2,%
fill=\PoolColor,opacity=0.5,height=12,width=6,depth=12}};
\pic[shift={(11.1,0,0)}] at (elt1-east) {Ball={name=elt2,%
fill=\SumColor,opacity=0.6,%
radius=2.5,logo=$+$}};
\pic[shift={(4.3,0,0)}] at (elt2-east) {Box={name=p6,caption=AveragePooling,%
fill=\PoolColor,opacity=0.5,height=46,width=8,depth=46}};
\pic[shift={(6.5,0,0)}] at (p6-east) {Box={name=p7,caption=GlobalAveragePooling,%
fill=\PoolColor,opacity=0.5,height=2,width=2,depth=150}};
\pic[shift={(4.5,0,0)}] at (p7-east) {Box={name=sigmoid,caption=Sigmoid,%
fill=\SoftmaxColor,%
height=1,width=1,depth=4}};
\pic[shift={(0,2,0)}] at (cr110-north) {RightBandedBox={name=score8,%
fill=\ConvColor,%
height=0,width=0,depth=0}};
\pic[shift={(6.3,0,0)}] at (cr1-east) {Box={name=d1,%
fill=\DcnvColor,%
height=0,width=0,depth=0}};
\pic[shift={(0,2,0)}] at (cr112-north) {RightBandedBox={name=score7,%
fill=\ConvColor,%
height=0,width=0,depth=0}};
\pic[shift={(6.3,0,0)}] at (cr11-east) {Box={name=d2,%
fill=\DcnvColor,%
height=0,width=0,depth=0}};
\pic[shift={(0,2.5,0)}] at (p2-north) {RightBandedBox={name=score6,%
fill=\ConvColor,%
height=0,width=0,depth=0}};
\pic[shift={(1,0,0)}] at (p2-east) {Box={name=d3,%
fill=\DcnvColor,%
height=0,width=0,depth=0}};
\pic[shift={(0,2.5,0)}] at (p3-north) {RightBandedBox={name=score61,%
fill=\ConvColor,%
height=0,width=0,depth=0}};
\pic[shift={(1,0,0)}] at (p3-east) {Box={name=d31,%
fill=\DcnvColor,%
height=0,width=0,depth=0}};
\pic[shift={(5,0,0)}] at (p3-east) {Box={name=d4,%
fill=\DcnvColor,%
height=0,width=0,depth=0}};
\pic[shift={(3,0,0)}] at (elt1-east) {Box={name=d5,%
fill=\DcnvColor,%
height=0,width=0,depth=0}};
\pic[shift={(2.4,0,0)}] at (d31-east) {Box={name=d6,%
fill=\DcnvColor,%
height=0,width=0,depth=0}};
\pic[shift={(2.2,0,0)}] at (elt1-east) {Box={name=d7,%
fill=\DcnvColor,%
height=0,width=0,depth=0}};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Draw connections
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw [connection] (cr1-east) -- node {\midarrow} (cr110-west);
\draw [connection] (cr110-east) -- node {\midarrow} (cr11-west);
\draw [connection] (cr11-east) -- node {\midarrow} (cr112-west);
\draw [connection] (cr112-east) -- node {\midarrow} (cr2-west);
\draw [connection] (p2-east) -- node {\midarrow} (cr3-west);
\draw [connection] (p6-east) -- node {\midarrow} (p7-west);
\draw [connection] (p7-east) -- node {\midarrow} (sigmoid-west);
\draw [connection] (d31-east) -- node {\midarrow} (d6-west);
\draw [connection] (elt1-east) -- node {\midarrow} (d7-west);
\draw [connection] (elt2-east) -- node {\midarrow} (p6-west);
\draw [connection] (p3-east) -- node {\midarrow} (d31-west);
\path (p3-east) -- (d4-west) coordinate[pos=0.68] (between3_6) ;
\draw [connection] (between3_6) -- node {\midarrow} (cr6-west-|between3_6) -- node {\midarrow} (cr6-west);
\draw [connection] (cr6-east) -- node {\midarrow} (cr6-east -| elt1-north) -- node {\midarrow} (elt1-north);
\path (p3-east) -- (d4-west) coordinate[pos=0.68] (between3_4) ;
\draw [connection] (between3_4) -- node {\midarrow} (cr4-west-|between3_4) -- node {\midarrow} (cr4-west);
\draw [connection] (cr42-east) -- node {\midarrow} (cr42-east -| elt1-north) -- node {\midarrow} (elt1-north);
\path (p3-east) -- (d4-west) coordinate[pos=0.68] (between3_5) ;
\draw [connection] (between3_5) -- node {\midarrow} (cr5-west-|between3_5) -- node {\midarrow} (cr5-west);
\draw [connection] (cr52-east) -- node {\midarrow} (cr52-east -| elt1-north) -- node {\midarrow} (elt1-north);
\path (p3-east) -- (d4-west) coordinate[pos=0.68] (between3_7) ;
\draw [connection] (between3_7) -- node {\midarrow} (cr7-west-|between3_7) -- node {\midarrow} (cr7-west);
\draw [connection] (p4-east) -- node {\midarrow} (p4-east -| elt1-north) -- node {\midarrow} (elt1-north);
\path (elt1-east) -- (d5-west) coordinate[pos=0.73] (between1_8) ;
\draw [connection] (between1_8) -- node {\midarrow} (cr8-west-|between1_8) -- node {\midarrow} (cr8-west);
\draw [connection] (cr82-east) -- node {\midarrow} (cr82-east -| elt2-north) -- node {\midarrow} (elt2-north);
\path (elt1-east) -- (d5-west) coordinate[pos=0.73] (between1_9) ;
\draw [connection] (between1_9) -- node {\midarrow} (cr9-west-|between1_9) -- node {\midarrow} (cr9-west);
\draw [connection] (cr92-east) -- node {\midarrow} (cr92-east -| elt2-north) -- node {\midarrow} (elt2-north);
\path (elt1-east) -- (d5-west) coordinate[pos=0.73] (between1_10) ;
\draw [connection] (between1_10) -- node {\midarrow} (cr10-west-|between1_10) -- node {\midarrow} (cr10-west);
\draw [connection] (cr10-east) -- node {\midarrow} (cr10-east -| elt2-north) -- node {\midarrow} (elt2-north);
\path (elt1-east) -- (d5-west) coordinate[pos=0.73] (between1_12) ;
\draw [connection] (between1_12) -- node {\midarrow} (cr7-west-|between1_12) -- node {\midarrow} (cr12-west);
\draw [connection] (p5-east) -- node {\midarrow} (p5-east -| elt2-north) -- node {\midarrow} (elt2-north);
\path (cr1-east) -- (cr110-west) coordinate[pos=0.45] (between1_110) ;
\draw [connection] (between1_110) -- node {\midarrow} (score8-west-|between1_110) -- node {\midarrow} (score8-west);
\draw [connection] (score8-east) -- node {\midarrow} (score8-east -| d1-north)-- node {\midarrow} (d1-north);
\path (cr11-east) -- (cr112-west) coordinate[pos=0.45] (between11_112) ;
\draw [connection] (between11_112) -- node {\midarrow} (score8-west-|between11_112) -- node {\midarrow} (score7-west);
\draw [connection] (score7-east) -- node {\midarrow} (score7-east -| d2-north)-- node {\midarrow} (d2-north);
\path (d2-east) -- (cr2-west) coordinate[pos=0.25] (between2_2) ;
\draw [connection] (between2_2) -- node {\midarrow} (score6-west-|between2_2) -- node {\midarrow} (score6-west);
\draw [connection] (score6-east) -- node {\midarrow} (score6-east -| d3-north)-- node {\midarrow} (d3-north);
\path (d3-east) -- (cr3-west) coordinate[pos=0.25] (between3_3) ;
\draw [connection] (between3_3) -- node {\midarrow} (score61-west-|between3_3) -- node {\midarrow} (score61-west);
\draw [connection] (score61-east) -- node {\midarrow} (score61-east -| d31-north)-- node {\midarrow} (d31-north);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{tikzpicture}
\end{document}\grid
LaTax卷积神经网络结构图(新)
于 2022-09-29 12:03:32 首次发布
该博客展示了如何使用 LaTeX 和 TikZ 库创建一个卷积神经网络(CNN)的详细可视化图,包括多个卷积层、池化层、全连接层以及反向传播过程中的得分层和反卷积层。内容涵盖了从输入图像到最终分类的整个流程。
摘要由CSDN通过智能技术生成