神经网络绘图工具PlotNeuralNet绘制折线

折线示意图

官方文档FCN-8网络示意图本文所指折线连接线如上图所示,详见官方文档FCN-8网络示意图:官方README
注:本文实现稍有差异,假定情况为所绘制的模块在主干网络“上方”,图中为“下方”。

使用Python接口绘制

  1. 在文件PlotNeuralNet-master/pycore/tikzeng.py中可见官方提供的绘图函数接口,实际上是返回一个字符串,在examples提供的fcn8.tex中可以看到以下内容:
    \draw [connection]  (between4_5)    -- node {\midarrow} (score16-west-|between4_5) -- node {\midarrow} (score16-west);
    \draw [connection]  (d32-east) -- node {\midarrow} (elt1-west);
    \draw [connection]  (score16-east) -- node {\midarrow} (score16-east -| elt1-south) -- node {\midarrow} (elt1-south);
    \draw [connection]  (elt1-east) -- node {\midarrow} (d16-west);
    
    其中第一第三行即为所需内容。
  2. 将其包装在tikzeng.py中,新增以下函数:
    def to_connection_right_down( of, to):
        '''
        Path: right, down
        '''
        return r"""
    \draw [connection]  ("""+of+"""-east)    -- node {\midarrow} ("""+of+"""-east -| """+to+"""-north) -- node {\midarrow} ("""+to+"""-north);
    """
    
    def to_connection_up_right( of, to):
        '''
        Path: up, right
        '''
        return r"""
    \draw [connection]  ("""+of+"""-north)    -- node {\midarrow} ("""+to+"""-west -| """+of+"""-north) -- node {\midarrow} ("""+to+"""-west);
    """
    
    其中函数to_connection_right_down()绘制从ofto的连接,连接路径为先向右后向下;to_connection_up_right()以此类推。
  3. 在原绘图文件中添加to_connection语句:
    to_connection_up_right( "enc_5", "att4"),
    to_connection_right_down( "att4", "dec_5"),
    

效果展示

效果如下图:

效果图

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值