HarisIqbal88 / PlotNeuralNet

Latex code for making neural networks diagrams
MIT License
21.74k stars 2.84k forks source link

Python code for examples #20

Open ianfoster opened 5 years ago

ianfoster commented 5 years ago

Congratulations on a wonderful project.

Would you be able to provide the Python code for Unet_Ushape and the other examples for which it is not currently provided?

Thanks much -- Ian

DEKHTIARJonathan commented 5 years ago

@HarisIqbal88 👍

vivid-chen commented 5 years ago

And I can't find where is Sum("+") node in Python code? but i can find it in FCN-8.

mbaharan commented 4 years ago

Thanks for the awesome work. Is there any update for Sum("+") node?

linxueya commented 4 years ago

@vivid-chen Jingze, have you found the SUM node in python code or any Alternative solutions?

omdxp commented 4 years ago

Can you provide a tutorial section in this project?

vivid-chen commented 4 years ago

@ vivid-chen Jingze,您是否在python代码或任何替代解决方案中找到了SUM节点?

I will upload the code later.

vivid-chen commented 4 years ago

You can read a simple code for example.

# a res block image
# china HUST CZY
# 2019 - 12 -27
import sys
sys.path.append('../')
from pycore.tikzeng import *
from pycore.blocks  import *

arch = [
    to_head( '../' ),
    to_cor(),
    to_begin(),

    # 输入图像 input image
    # to_input( '../examples/fcn8s/cats.jpg' ),

    # block-1
    # to_Conv("conv1", 24, 64, offset="(0,0,0)", to="(0,0,0)", height=24, depth=24, width=2 ),
    to_node(name="node1", offset="(0,0,0)", to="(0,0,0)",radius=0.001, opacity=0, logo=" " ),

    # block-2 resblock1
    to_Conv("res1_conv1", 24, 64, offset="(3,0,0)", to="(node1-east)", height=24, depth=24, width=2, caption="Conv1"  ),
    to_Pool(name="res1_relu", offset="(1.5,0,0)", to="(res1_conv1-east)", width=1, height=24, depth=24, opacity=0.5, caption="ReLU" ),
    to_Conv("res1_conv2", 24, 64, offset="(1.5,0,0)", to="(res1_relu-east)",height=24, depth=24, width=2, caption="Conv2" ),
    to_node(name="res1_sum", offset="(1.5,0,0)", to="(res1_conv2-east)",radius=1.8, opacity=0.8, logo="+", caption="+" ),

    to_node(name="res1_node1", offset="(2,0,0)", to="(node1-east)",radius=0.001, opacity=0, logo=" " ),
    to_node(name="res1_node2", offset="(2,0,4)", to="(node1-east)",radius=0.001, opacity=0, logo=" " ),
    to_node(name="res1_node3", offset="(1.5,0,4)", to="(res1_conv2-east)",radius=0.001, opacity=0, logo=" " ),
    to_node(name="res1_node4", offset="(1.5,0,0)", to="(res1_conv2-east)",radius=0.001, opacity=0, logo=" " ),

    # 折线 broken line
    to_connection_choose( "res1_node1-east", "res1_node2-east"),
    to_connection_choose( "res1_node2-east", "res1_node3-east"),
    to_connection_choose( "res1_node3-east", "res1_node4-east"),

    # 直线 straight line
    to_connection( "node1", "res1_node1"),
    to_connection( "res1_node1", "res1_conv1"),
    to_connection( "res1_conv1", "res1_relu"),
    to_connection( "res1_relu", "res1_conv2"),
    to_connection( "res1_conv2", "res1_node4"),

    # block-3
    # to_ConvRes( "convres", s_filer=256, n_filer=64, offset="(5,0,0)", to="(res1_conv2-east)", width=6, height=40, depth=40, opacity=0.2, caption=" " ),
    to_node(name="node2", offset="(3,0,0)", to="(res1_conv2-east)",radius=0.001, opacity=0, logo=" " ),
    to_connection( "res1_node4", "node2"),

    # to_node( "sum", offset="(10,0,0)", to="(res1_conv2-east)", radius=2.5, opacity=0.6, logo="+"),
    # to_connection( "convres", "sum"),

    to_end()
    ]

def main():
    namefile = str(sys.argv[0]).split('.')[0]
    to_generate(arch, namefile + '.tex' )

if __name__ == '__main__':
    main()

my_arch.pdf

linxueya commented 4 years ago

You can read a simple code for example.

# a res block image
# china HUST CZY
# 2019 - 12 -27
import sys
sys.path.append('../')
from pycore.tikzeng import *
from pycore.blocks  import *

arch = [
    to_head( '../' ),
    to_cor(),
    to_begin(),

    # 输入图像 input image
    # to_input( '../examples/fcn8s/cats.jpg' ),

    # block-1
    # to_Conv("conv1", 24, 64, offset="(0,0,0)", to="(0,0,0)", height=24, depth=24, width=2 ),
    to_node(name="node1", offset="(0,0,0)", to="(0,0,0)",radius=0.001, opacity=0, logo=" " ),

    # block-2 resblock1
    to_Conv("res1_conv1", 24, 64, offset="(3,0,0)", to="(node1-east)", height=24, depth=24, width=2, caption="Conv1"  ),
    to_Pool(name="res1_relu", offset="(1.5,0,0)", to="(res1_conv1-east)", width=1, height=24, depth=24, opacity=0.5, caption="ReLU" ),
    to_Conv("res1_conv2", 24, 64, offset="(1.5,0,0)", to="(res1_relu-east)",height=24, depth=24, width=2, caption="Conv2" ),
    to_node(name="res1_sum", offset="(1.5,0,0)", to="(res1_conv2-east)",radius=1.8, opacity=0.8, logo="+", caption="+" ),

    to_node(name="res1_node1", offset="(2,0,0)", to="(node1-east)",radius=0.001, opacity=0, logo=" " ),
    to_node(name="res1_node2", offset="(2,0,4)", to="(node1-east)",radius=0.001, opacity=0, logo=" " ),
    to_node(name="res1_node3", offset="(1.5,0,4)", to="(res1_conv2-east)",radius=0.001, opacity=0, logo=" " ),
    to_node(name="res1_node4", offset="(1.5,0,0)", to="(res1_conv2-east)",radius=0.001, opacity=0, logo=" " ),

    # 折线 broken line
    to_connection_choose( "res1_node1-east", "res1_node2-east"),
    to_connection_choose( "res1_node2-east", "res1_node3-east"),
    to_connection_choose( "res1_node3-east", "res1_node4-east"),

    # 直线 straight line
    to_connection( "node1", "res1_node1"),
    to_connection( "res1_node1", "res1_conv1"),
    to_connection( "res1_conv1", "res1_relu"),
    to_connection( "res1_relu", "res1_conv2"),
    to_connection( "res1_conv2", "res1_node4"),

    # block-3
    # to_ConvRes( "convres", s_filer=256, n_filer=64, offset="(5,0,0)", to="(res1_conv2-east)", width=6, height=40, depth=40, opacity=0.2, caption=" " ),
    to_node(name="node2", offset="(3,0,0)", to="(res1_conv2-east)",radius=0.001, opacity=0, logo=" " ),
    to_connection( "res1_node4", "node2"),

    # to_node( "sum", offset="(10,0,0)", to="(res1_conv2-east)", radius=2.5, opacity=0.6, logo="+"),
    # to_connection( "convres", "sum"),

    to_end()
    ]

def main():
    namefile = str(sys.argv[0]).split('.')[0]
    to_generate(arch, namefile + '.tex' )

if __name__ == '__main__':
    main()

my_arch.pdf

老铁,我自己看latex源码知道怎么实现了

linxueya commented 4 years ago

the code of SUM node

def to_add( name, to, offset="(0,0,0)", opacity=0.4, caption=''):
    return r"""
\pic[shift={"""+ offset +"""}] at """+ to +""" 
    {Ball={
        name=""" + name +""",
        caption="""+ caption +""",
        fill=\SumColor,
        opacity="""+ str(opacity) +""",
        radius=2.5,
        logo=$+$
        }
    };
"""
tomlof commented 4 years ago

Thanks for a great package!

Is there a reason the corresponding Python code is not included in the examples? This issue is over a year old, and no code yet. It would make using the package much easier...

Does anyone know of any tutorials, or examples where this package is explained? In particular, I'd like to know how to add fully connected layers.

chrismaliszewski commented 4 years ago

I was also looking for the fully connected layers and since I didn't find it in the latest version I created it based on another function.

Here you have the code https://github.com/HarisIqbal88/PlotNeuralNet/issues/82.

matthijsvk commented 3 years ago

@linxueya, that looks very nice; do you have the code for the to_node() and to_connection_choose() functions as well?

AlexandreBourrieau commented 2 years ago

Hello, can you post to_node() please ??? thanks !

chrismaliszewski commented 2 years ago

I went back to the old code not that long ago and it also doesn't work for me. I gave up and decided to create models directly from Overleaf.

@matthijsvk, @AlexandreBourrieau, I search the whole dir structure for the functions but couldn't find them. In which file does the function suppose to be?

EchoJJ51 commented 11 months ago

,看起来非常好;您是否也有 to_node() 和 to_connection_choose() 函数的代码?

to_connection( “node1”, “res1_node1”),//This can be achieved with the original linear function // This is the generated tex file, find the straight line function of sentences modify it \path (conv1-southeast) -- (conv1-northeast) coordinate[pos=1.1] (conv1-top) ; \path (conv4-south) -- (conv4-north) coordinate[pos=11] (conv4-top) ;///Just adjust the value here pos = value