卷积神经网络画图神器PlotNeuralNet(基于Latex)使用记录

PlotNeuralNet工具是一个基于Latex,同时可用Python交互的卷积神经网络画图工具

目录

  • 1、安装使用与样例
  • 2、基本layer, block or unit的Latex语句
    • (1)层
    • (2)层的组合
    • (3)残差结构

1、安装使用与样例

Github下载地址

一个例子,具体的安装与使用介绍看Github:
卷积神经网络画图神器PlotNeuralNet(基于Latex)使用记录_第1张图片

2、基本layer, block or unit的Latex语句

Latex文本可在~\PlotNeuralNet\examples\fcn8s 下直接运行成功

(1)层

卷积神经网络画图神器PlotNeuralNet(基于Latex)使用记录_第2张图片

\documentclass[border=15pt, multi, tikz]{standalone}
\usepackage{import}
\subimport{../../layers/}{init}
\usetikzlibrary{positioning}
\usetikzlibrary{3d} %for including external image 

\def\ReLUColor{rgb:red,1;black,0.3}

\begin{document}
\begin{tikzpicture}
\tikzstyle{connection}=[ultra thick,every node/.style={sloped,allow upside down},draw=\edgecolor,opacity=0.7]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Draw Layer Blocks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% one layer for a conv or BN or ReLU layer, etc
\pic[shift={(0,0,0)}] at  (0,0,0) {Box={name=score16,%
            xlabel={{"K"}},fill=\ReLUColor,%
            height=15,width=2,depth=15}};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{tikzpicture}
\end{document}\grid

(2)层的组合

CNN网络中,通常有conv+BN+ReLU这样子的层组合
卷积神经网络画图神器PlotNeuralNet(基于Latex)使用记录_第3张图片

\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\BnColor{rgb:yellow,5;red,5;white,5}
\def\ReLUColor{rgb:red,1;black,0.3}


\begin{document}
\begin{tikzpicture}
\tikzstyle{connection}=[ultra thick,every node/.style={sloped,allow upside down},draw=\edgecolor,opacity=0.7]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Draw Layer Blocks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% conv+bn+relu
\pic[shift={(0,0,0)}] at  (0,0,0) {Box={name=conv1,%
            xlabel={{6}},fill=\ConvColor,%
            height=40,width=1,depth=40}};
\pic[shift={(0,0,0)}] at (conv1-east) {Box={name=bn1,%
        	 xlabel={{4}},fill=\BnColor,%
			 opacity=0.5,height=40,width=1,depth=40}};
\pic[shift={(0,0,0)}] at (bn1-east) {Box={name=relu1,%
        	 fill=\ReLUColor,opacity=0.5,height=40,width=1,depth=40,zlabel = I}};

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{tikzpicture}
\end{document}\grid

(3)残差结构

卷积神经网络画图神器PlotNeuralNet(基于Latex)使用记录_第4张图片

\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\ConvBnReluColor{rgb:yellow,5;red,5;white,2.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}

\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,%pool1
\pic[shift={(0,0,0)}] at (0,0,0) {RightBandedBox={name=cr1,caption=conv1,%
        xlabel={{"64","64"}},zlabel=I,fill=\ConvColor,bandfill=\ConvBnReluColor,%
        height=40,width={2,2},depth=40}};
\pic[shift={(0,0,0)}] at (cr1-east) {Box={name=p1,%
        fill=\PoolColor,opacity=0.5,height=35,width=1,depth=35}};

\pic[shift={(3,0,0)}] at (p1-east) {Ball={name=elt1,%
        fill=\SumColor,opacity=0.6,%
        radius=2.5,logo=$+$}};


%% score16
\pic[shift={(0,-4,0)}] at (elt1-west) {Box={name=score16,%
            fill=\PoolColor,%
            opacity=0,height=0.01,width=0.01,depth=0.01}};
%% draw connections
%\draw [connection]  (p1-east) -- node {\midarrow} (p1-east -| elt1-west) -- node {\midarrow} (elt1-west);
\draw [connection]  (p1-east)    -- node {\midarrow} (elt1-west);
\path (p1-east) -- (elt1-south) coordinate[pos=0.25] (between4_5) ;
\draw [connection]  (between4_5)    -- node {\midarrow} (score16-west-|between4_5) -- node {\midarrow} (score16-west);
\draw [connection]  (score16-east) -- node {\midarrow} (score16-east -| elt1-south) -- node {\midarrow} (elt1-south);
\draw [connection]  (p1-east)    -- node {\midarrow} (elt1-west);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{tikzpicture}
\end{document}\grid

你可能感兴趣的:(Latex,毕设)