PlotNeuralNet使用总结

PlotNeuralNet使用总结

一、主要函数

to_Pool()
to_Conv()
to_connection()
to_ConvConvRelu()
to_skip()

1. to_Conv

image-20240309210313468

  • name: 该层的名称,不会在图中显示,类似于变量名,用该名称可以标识该层
  • s_filer: 显示在图像的尺寸,不影响图像实际绘制效果
  • n_filer: 显示在图像中的通道数,不影响图像实际绘制效果
  • offset: 分别是x,y,z三个方向的绝对偏移量
  • to: 可以使该层相对于 offset 设定后的坐标在 x,y,z 方向上偏移,也可以指示该层连接到某一层的左边(west)或者右边(east) ,例如 to="(conv11-east)" 表示该层连接到 name="conv11" 的右边
  • width: 厚度
  • height: 高度
  • depth: 宽度
  • caption: 显示该层名称,不影响图像实际绘制效果

2. to_Pool

image-20240309211337793

  • name: 该层的名称,不会在图中显示,类似于变量名,用该名称可以标识该层
  • offset: 分别是x,y,z三个方向的绝对偏移量
  • to: 可以使该层相对于 offset 设定后的坐标在 x,y,z 方向上偏移,也可以指示该层连接到某一层的左边(west)或者右边 (east) ,例如 to="(conv11-east)" 表示该层连接到 name="conv11" 的右边
  • width: 厚度
  • height: 高度
  • depth: 宽度
  • opacity: 透明度
  • caption: 显示该层名称,不影响图像实际绘制效果

3. to_connection()

image-20240309212353040

  • of: 连接线起始层的名称
  • to: 连接线目标层的名称

note: #to_connection 要放在要连接的两层之后,也就是说,两层都创建了之后,才能创建二者之间的连接线

4 . to_skip()

  • of: 连接线起始层的名称
  • to: 连接线目标层的名称
  • pos:控制跳接的线与块的距离

note: #to_connection 要放在要连接的两层之后,也就是说,两层都创建了之后,才能创建二者之间的连接线

二、创建自定义块的方法

image-20240309213750291

不同的块本质上也就是颜色的不同而已,而长宽厚度本身本就是可以定义的,因此实质上我们可以自己定义一个新的块,只需要在原本的块的基础上改变其颜色的定义

创建自定义块的方法具体过程

首先找到所有块定义的文件,tikzeng.py中定义了常用的基本块,例如卷积、池化等块。

卷积块函数的定义如下:

# Conv
def to_Conv( name, s_filer=256, n_filer=64, offset="(0,0,0)", to="(0,0,0)", width=1, height=40, depth=40, caption=" " ):
return r"""
\pic[shift={"""+ offset +"""}] at """+ to +"""
{Box={
name=""" + name +""",
caption="""+ caption +r""",
xlabel={{"""+ str(n_filer) +""", }},
zlabel="""+ str(s_filer) +""",
fill=\ConvColor,
height="""+ str(height) +""",
width="""+ str(width) +""",
depth="""+ str(depth) +"""
}
};
"""

可以看到第10行定义了填充卷积块的颜色,因此直接全文搜索ConvColor的定义,发现关于ConvColor的内容定义在同文件下的to_cor()函数下方,虽然不知道为什么rgb定义它却有white和black,不过测试发现,通常的rgb(red,green,blue)是没有问题的。

def to_cor():
return r"""
\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}
\def\NormColor{rgb:red,100;green,149;blue,237}
"""

在上面的代码中,我在第11行定义了NormColor​,该颜色如下图:image-20240309214730796

接着创建一个名为to_Norm()的函数,这里我直接复制了to_Conv(),然后将其的函数名改为to_Norm(),并将填充色改为\NormColor,值得注意的是'\n'在Python中表示换行符,因此要使用\\NormColor来转义。具体函数内容如下:

# Norm
def to_Norm( name, s_filer=256, n_filer=64, offset="(0,0,0)", to="(0,0,0)", width=1, height=40, depth=40, caption=" " ):
return r"""
\pic[shift={"""+ offset +"""}] at """+ to +"""
{Box={
name=""" + name +""",
caption="""+ caption +r""",
xlabel={{"""+ str(n_filer) +""", }},
zlabel="""+ str(s_filer) +""",
fill=\\NormColor,
height="""+ str(height) +""",
width="""+ str(width) +""",
depth="""+ str(depth) +"""
}
};
"""
posted @   贰拾散人  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 推荐几款开源且免费的 .NET MAUI 组件库
· 实操Deepseek接入个人知识库
· 易语言 —— 开山篇
· Trae初体验
点击右上角即可分享
微信分享提示