引言
- 介紹如何安裝PlotNeuralNet工具,并結(jié)合chatGPT減少學(xué)習(xí)成本,快速出圖。
- 將按照軟件安裝和軟件使用,以及最終使用結(jié)果四個(gè)部分進(jìn)行介紹。
正文
PlotNeuralNet
- PlotNeuralNet是一個(gè)帶有python借口的latex包,能夠生成任何你需要的神經(jīng)網(wǎng)絡(luò)的可視化圖片。生成的圖片質(zhì)量很高,可以用于課程匯報(bào),或者學(xué)術(shù)論文。
- 你可以直接使用latex編譯程序,編寫相關(guān)的代碼,自動(dòng)會(huì)生成對(duì)應(yīng)的圖片。我一般是使用overleaf寫的latex代碼,線上可以直接渲染,并下載對(duì)應(yīng)的pdf文件
- overleaf鏈接:Overleaf
安裝
- 1、在ubuntu系統(tǒng)中安裝如下包
- Ubuntu 16.04系統(tǒng)
sudo apt-get install texlive-latex-extra
- Ubuntu 18.04.2輸入如下指令進(jìn)行安裝
- 這里是需要你安裝一個(gè)叫做pdflatex的軟件,能夠?qū)atex的代碼tex轉(zhuǎn)成對(duì)應(yīng)的pdf。具體安裝指令如下
sudo apt-get install texlive-latex-base
sudo apt-get install texlive-fonts-recommended
sudo apt-get install texlive-fonts-extra
sudo apt-get install texlive-latex-extra
- 將latex代碼文件tex后綴的,轉(zhuǎn)成對(duì)應(yīng)的pdf文件,具體指令見下方
pdflatex latex_source_name.tex
-
windows平臺(tái)
- 下載并安裝MikeTex軟件,下載鏈接
- 下載并安裝windows上運(yùn)行的bash運(yùn)行工具,推薦使用git的bash工具或者Cygwin
- git下載鏈接
- Cygwin下載鏈接
-
2、運(yùn)行如下指令
cd pyexamples/
bash ../tikzmake.sh test_simple
-
這里可以看一下測(cè)試樣例的python代碼
-
完整的圖片對(duì)應(yīng)的latex代碼
\documentclass[border=8pt, 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\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}
\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]
\tikzstyle{copyconnection}=[ultra thick,every node/.style={sloped,allow upside down},draw={rgb:blue,4;red,1;green,1;black,3},opacity=0.7]
\pic[shift={(0,0,0)}] at (0,0,0)
{Box={
name=conv1,
caption= ,
xlabel={{64, }},
zlabel=512,
fill=\ConvColor,
height=64,
width=2,
depth=64
}
};
\pic[shift={ (0,0,0) }] at (conv1-east)
{Box={
name=pool1,
caption= ,
fill=\PoolColor,
opacity=0.5,
height=32,
width=1,
depth=32
}
};
\pic[shift={(1,0,0)}] at (pool1-east)
{Box={
name=conv2,
caption= ,
xlabel={{64, }},
zlabel=128,
fill=\ConvColor,
height=32,
width=2,
depth=32
}
};
\draw [connection] (pool1-east) -- node {\midarrow} (conv2-west);
\pic[shift={ (0,0,0) }] at (conv2-east)
{Box={
name=pool2,
caption= ,
fill=\PoolColor,
opacity=0.5,
height=28,
width=1,
depth=28
}
};
\pic[shift={(3,0,0)}] at (pool1-east)
{Box={
name=soft1,
caption=SOFT,
xlabel={{" ","dummy"}},
zlabel=10,
fill=\SoftmaxColor,
opacity=0.8,
height=3,
width=1.5,
depth=25
}
};
\draw [connection] (pool2-east) -- node {\midarrow} (soft1-west);
\pic[shift={(1.5,0,0)}] at (soft1-east)
{Ball={
name=sum1,
fill=\SumColor,
opacity=0.6,
radius=2.5,
logo=$+$
}
};
\draw [connection] (soft1-east) -- node {\midarrow} (sum1-west);
\end{tikzpicture}
\end{document}
使用
使用python進(jìn)行編輯
- 具體的python編寫代碼
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_Sum("sum1", offset="(1.5,0,0)", to="(soft1-east)", radius=2.5, opacity=0.6),
to_connection("soft1", "sum1"),
to_end()
]
def main():
namefile = str(sys.argv[0]).split('.')[0]
to_generate(arch, namefile + '.tex' )
if __name__ == '__main__':
main()
- 注意切換到當(dāng)前python對(duì)應(yīng)的路徑下方,運(yùn)行如下指令
cd pyexamples/
bash ../tikzmake.sh test_simple
使用latex進(jìn)行編輯
- 這里我是使用overleaf進(jìn)行編輯的,也是參考了別人的模板,具體鏈接
- overleaf模板:鏈接
- 不要?jiǎng)觢ayers中的包,只需要改變main.tex就可
樣例
利用chatGPT
使用chatGPT生成Latex代碼
- 按照網(wǎng)上的教程,這里需要先給他一個(gè)樣例,并且這個(gè)樣例和你需要畫的文件具有一定的相似性,然后讓chatGPT幫你生成,具體指令如下
這是生成CNN的latex代碼,使用的是PlotNeuralNet的Latex包,根據(jù)這個(gè)代碼,幫我寫一下FCN的latex代碼
- 生成效果如下
- 他生成的總歸有一些問(wèn)題,這個(gè)時(shí)候,你需要根據(jù)模型的實(shí)際內(nèi)容進(jìn)行修改。
- 我也試驗(yàn)了直接生成對(duì)應(yīng)的模型,看了一下具體的效果
- 這里直接讓他生成unet模型,它只能生成特定的模塊,并不能生成完整的網(wǎng)絡(luò)模型
- 根據(jù)具體的操作過(guò)程,在后續(xù)的過(guò)程中,會(huì)更新
利用chatGPT生成對(duì)應(yīng)的python代碼
- chatGPT默認(rèn)的PlotNeuralNet是一個(gè)Latex包,其中并沒有python的接口,所以并不能生成對(duì)應(yīng)的代碼。直接生成不現(xiàn)實(shí)。
- 這里還是嘗試先給他一個(gè)代碼樣例,然后在提出對(duì)應(yīng)的要求。效果良好。
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-601149.html
- 但是,注意,PlotNeuralNet的python接口支持的組件不多,有一部分的模型畫不出來(lái),僅僅支持一下的幾種
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-601149.html
總結(jié)
- 使用這個(gè)工具,雖然不能完全不需要寫代碼 ,但是盡可能減少了我所需要寫的編碼量,只需要編寫局部就行了。不過(guò)還是需要能看懂,然后才能進(jìn)行改錯(cuò)。
引用
- Creating Stunning Neural Network Visualizations with ChatGPT and PlotNeuralNet
- PlotNeuralNet
到了這里,關(guān)于論文工具——ChatGPT結(jié)合PlotNeuralNet快速出神經(jīng)網(wǎng)絡(luò)深度學(xué)習(xí)模型圖的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!