Coder Social home page Coder Social logo

plotneuralnet's Introduction

PlotNeuralNet

DOI

Latex code for drawing neural networks for reports and presentation. Have a look into examples to see how they are made. Additionally, lets consolidate any improvements that you make and fix any bugs to help more people with this code.

Examples

Following are some network representations:

Holistically-Nested Edge Detection (view on Overleaf)

Getting Started

  1. Install the following packages on Ubuntu.

    • Ubuntu 16.04

      sudo apt-get install texlive-latex-extra
      
    • Ubuntu 18.04.2 Base on this website, please install the following packages.

      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
      
    • Windows

    1. Download and install MikTeX.
    2. Download and install bash runner on Windows, recommends Git bash or Cygwin(https://www.cygwin.com/)
  2. Execute the example as followed.

    cd pyexamples/
    bash ../tikzmake.sh test_simple
    

TODO

  • Python interface
  • Add easy legend functionality
  • Add more layer shapes like TruncatedPyramid, 2DSheet etc
  • Add examples for RNN and likes.

Latex usage

See examples directory for usage.

Python usage

First, create a new directory and a new Python file:

$ mkdir my_project
$ cd my_project
vim my_arch.py

Add the following code to your new file:

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_end()
    ]

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

if __name__ == '__main__':
    main()

Now, run the program as follows:

bash ../tikzmake.sh my_arch

plotneuralnet's People

Contributors

alyetama avatar brandon-hy-lin avatar harisiqbal88 avatar jackyko1991 avatar lukasliebel avatar mbrukman avatar pedrodiamel avatar stevenshi-23 avatar weiji14 avatar weslynn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plotneuralnet's Issues

Edge Thickness

Is it possible to change the thickness of the edges along a shape (such as a Box)? If so, how?

Thanks!

Labeling Blocks will create a solid line

I tried to let the Box block's edges be invisible via fill=\fill, draw=\fill in Box.sty.

Actually, It only let edges AH, AD, DE, CD, EF and HE invisible.

Finally I found that \path (b) edge ["\bf\xlabel"', midway] (c); created a solid line in BC, so do AB and CF.

I have no idea to fix this and I don't know why the solid lines emerged though no pic action acted in above code.

Furthermore, I want customize the style of draw line, but nothing changes after I put thin into "box" style setting.

xdg-open instead of hard coding evince

Hey there,
great work !

I got just a small suggestion, the script ../tikzmake.sh hardcodes the evince pdf reader. However, not everybody uses that one.
Could I just change that like to:

#!/bin/bash


python $1.py 
pdflatex $1.tex

rm *.aux *.log *.vscodeLog
rm *.tex

xdg-open $1.pdf

In order to be a bit more compatible, even though thats a small issue

Zlabel Position Error

I just run fc8 from the example dir. I don't know why the position of Z-label is wrong ...
1

Suggestion for generating latex codes

It is an awesome project.
It is recommended to generate latex codes with pylatex, that makes the codes readable and extensible. Of course, you have to spend some time on it.

[Q]: How to do connection west - east ?

Unfortunately I'm not sure about the syntax in python.
And i don't want to change it every time in Latex.
\draw [connection] (dense_1-west) -- node {\midarrow} (reshape_1-east);

Thank you,
Vaclav

ResNet50 Tex

Will it be possible to get .tex for ResNet50?

When I am trying to define the architecture in python example: arch.py and then use the command "./tikzmake.sh arch" it is not working and giving me the following error:

Traceback (most recent call last):
File "arch.py", line 4, in
from pycore.tikzeng import *
ModuleNotFoundError: No module named 'pycore.tikzeng'
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
! I can't find file `arch.tex'.
<*> arch.tex

(Press Enter to retry, or Control-D to exit)
Please type another input file name:

BatchNorm

Nice project! A batch normalization element would be cool...

【help】HED

Thank you very much for your great work.
I want to draw the network structure of HED, but it has not been successful for a long time.
Can anyone share the original code of drawing HED? The deadline is coming. T-T
I'll be grateful.

Font size in the graph

Does anyone know how to change the font size in the graph? I tried to simply add to the documentclass

\documentclass[border=15pt, multi, tikz]{standalone}

but it doesn't work and returns some errors with positioning.

Suggested change to_ConvConvRelu

Hi. I was working with your code (great, by the way!) and, while using "to_ConvConvRelu", I realized that it could be easily be extended to any number of Convs:

def to_ConvConvRelu( name, s_filer=256, n_filer=(64,64), offset="(0,0,0)", to="(0,0,0)", width=(2,2), height=40, depth=40, caption=" " ):
    return r"""
\pic[shift={ """+ offset +""" }] at """+ to +""" 
    {RightBandedBox={
        name="""+ name +""",
        caption="""+ caption +""",
        xlabel={{ """+ ''.join([str(n_filer[i]) + """, """ for i in range(len(n_filer)-1)])+ str(n_filer[-1]) +""" }},
        zlabel="""+ str(s_filer) +""",
        fill=\ConvColor,
        bandfill=\ConvReluColor,
        height="""+ str(height) +""",
        width={ """+ ''.join([str(width[i]) + """, """ for i in range(len(width)-1)])+ str(width[-1]) +""" },
        depth="""+ str(depth) +"""
        }
    };
"""

Sorry for the not really clean code; there's surely a way of coding it that is not as dirty but it does the trick.

Regards,
Guille

Error when running readme example: `I can't find file `tikzlibraryquotes.code.tex'`

python my_arch.py works fine, producing the output included below. However, when I run pdflatex , I get error:

! I can't find file `tikzlibraryquotes.code.tex'.
<argument> ...nput tikzlibrary\pgf@temp .code.tex 
                                                  \catcode `\@ =\csname tikz...
l.2 \usetikzlibrary{quotes,arrows.meta}

I presume this is a simple fix requiring an install. Please may you help me diagnose what I need installed on my system for this to run? I am able to run tikz fine and create examples e.g. this one.

LaTeX info

$ pdflatex --version
pdfTeX 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian)
kpathsea version 6.1.1
Copyright 2013 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.2.50; using libpng 1.2.50
Compiled with zlib 1.2.8; using zlib 1.2.8
Compiled with poppler version 0.24.5

Python output:

\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}   


\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);


\end{tikzpicture}
\end{document}

unet error

pyexamples|master⚡ ⇒ bash ../tikzmake.sh unet

File "unet.py", line 19
block_2ConvPool( name='b2', botton='pool_b1', top='pool_b2', s_filer=256, n_filer=128, offset="(1,0,0)", size=(32,32,3.5), opacity=0.5 ),
^
SyntaxError: invalid syntax
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
! I can't find file `unet.tex'.
<
> unet.tex

(Press Enter to retry, or Control-D to exit)
Please type another input file name: ^D
! Emergency stop.
<*> unet.tex

! ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.
rm: *.aux: No such file or directory
rm: *.vscodeLog: No such file or directory
rm: *.tex: No such file or directory
../tikzmake.sh: line 10: xdg-open: command not found

pdflatex + evince error

Hi awesome team,
I was trying to run example in the readme, was able to get the latex printed out in terminal but...

../tikzmake.sh: line 5: pdflatex: command not found
rm: *.aux: No such file or directory
rm: *.log: No such file or directory
rm: *.vscodeLog: No such file or directory
../tikzmake.sh: line 10: evince: command not found
line 5: pdflatex: command not found

Is there a way to not use these two?

Unet to DenseNets

I am trying to modify Unet tex code to create DenseNets block.
f838717a-6ad1-11e6-9391-f0906c80bc1d

I am wondering how to modify the connection lines that then look like densenets style?
Thank you for your time!

Is there a way to add legend?

Hi, I wonder if there is a way of adding legend to the figure (identifying which color corresponds to which type of layer).

A example would like the original U-Net figure:

screen shot 2018-11-29 at 12 37 17 am

I want to know how to add legend

Hi, I wonder if there is a way of adding legend to the figure (identifying which color corresponds to which type of layer).

A example
default

And how to eliminate cube number?

Add a License

Hi,
first of all let me say the visualization you have created here is looking excellent! I was thinking about using it, but I have noticed that there is no license included in the project. Could you please add one? You could check out choosealicense.com if you are unsure which license fits your needs.
Thank you very much.

Error in readme example

In the examples section of the readme, the figure displayed is not VGG16, it is a FCN without the skip connections

subimport path error on windows

On windows, the path is connected by \ rather than /, which may cause some latex environment not recognize the subimport path correctly, e.g. on my machine (python 3.7 win10 x64), it produce

\subimport{..\layers/}{init}

but latexpdf complains about not find the path, it should be

\subimport{../layers/}{init}

Transfer learning

Hi, is there a way to visualize transfer learning? means two parallel network and connections between them? or some hack in mind?

Thanks!

Cant get to_connection to work properly

arch = [
    to_head( '..' ),
    to_cor(),
    to_begin(),
    to_Conv("conv1", 320, 8, offset="(0,0,0)", to="(0,0,0)", height=64, depth=64, width=8),
    to_Pool("pool1", offset="(0,0,0)", to="(conv1-east)", height=60, depth=60, width=1),

    to_Conv("conv2", 160, 16, offset="(1,0,0)", to="(pool1-east)", height=32, depth=32, width=16),
    to_Pool("pool2", offset="(0,0,0)", to="(conv2-east)", height=30, depth=30, width=1),

    to_Conv("conv3", 80, 32, offset="(0,0,0)", to="(pool2-east)", height=16, depth=16, width=32),
    to_Pool("pool3", offset="(0,0,0)", to="(conv3-east)", height=1, depth=1, width=32, caption='GlobalAveragePooling'),

    to_SoftMax("soft1", 8 ,"(0,0,0)", "(pool3-east)", caption="fc1"),
    to_connection( "soft2", "soft1"),
    to_SoftMax("soft2", 1 ,"(1,0,0)", "(soft1-east)", caption="fc2", height=1, width=1, depth=1),
    to_end()
    ]

The above makes a green arrow through the whole network instead of the last 2 layers. Why?

citation

Hello
How do you want us to cite your work?

box edge colors

how to change the color of layer box from black to white or any other color. thanks.

Captioning the box will create a black dot only shown on Windows

Hi, @HarisIqbal88

I am back again 😸 ! I found that labeling a caption will make a black dot by the following code. Though it's invisible on my Mac OS and Ubuntu, I found it when I open the pdf on Windows, using Adobe reader exactly.

\path (\LastEastx/2,-\y/2,+\z/2) + (0,-25pt) coordinate (cap) 
        edge ["\textcolor{black}{ \bf \caption}"',captionlabel](cap) ; %Block caption/pic object label

I am wondering that the way you make labels by adding a edge, but the tutorials in TiKz always use node, which seems malfunctioned in your repo. (Maybe I use the node syntax wrongly)

default

to_input(...) doesn't have east, west... properties

I would like to connect the input image to conv blocks and other blocks, but it is not possible since to_input(...) doesn't have east, west, northeast, etc... properties. How to solve this? Maybe wrap to_input(...) in a box or something?

Drawing only one conv layer

Hello,
thank you for this awesome project. If I draw only one conv layer like this:

\pic[shift={(0,0,0)}] at (0,0,0) {RightBandedBox={name=cr1,caption=conv1,%
        xlabel={{"96", ""}},ylabel=224,zlabel=224,fill=\ConvColor,bandfill=\ConvReluColor,%
        height=40,width={2},depth=40}};

then I have to keep xlabel as xlabel={{"96", ""}} with an empty qoutation marks. Is there a way to eliminate this need?

Problem when test example

Hi,everyone,when i follow the step in readme, I met a lot of problem.
I enter the name but it print the same thing.
It seems that I lack something. But I don't what is it. T^T
Screenshot from 2019-10-04 16-34-54

Way to change the fontsize

Hi, thank you for this awesome project! I am new to LaTex and just wondering is there any way for me to define or change the fontsize for the caption or the depthlabel? Thanks you!

Drawing the kernel dimensions in a conv layer

Hi,

Great library, very useful. I am writing a book for Cambridge University Press and would like to use it to explain CNNs. One feature that's missing is drawing the kernel dimensions (e.g. 3x3 or 5x5 or 11x11). Do you have any suggestions how to do that?

Michel

Importing layers in a latex project will affect captions on all figure boxes

Importing the 'layers' folder in a latex project will affect captions in every figure and table boxes. Basically, every caption will not have anymore the text "Figure X"/"Table X" where X is a index as soon as you add the lines \subimport{layers/}{init} .

Minimum example (correct):

\documentclass{article}

\usepackage{graphicx}
% \usepackage{tikz}
% \usepackage{import}
% \subimport{layers/}{init}
% \usetikzlibrary{positioning}

\begin{document}

\begin{figure}
    \centering
    \includegraphics[height=5cm]{cats.jpg}
    \caption{This is a caption.}
    \label{test2}
\end{figure}

\end{document}

This produces:
image

Importing layers:

\documentclass{article}

\usepackage{graphicx}
\usepackage{tikz}
\usepackage{import}
\subimport{layers/}{init}
\usetikzlibrary{positioning}

\begin{document}

\begin{figure}
    \centering
    \includegraphics[height=5cm]{cats.jpg}
    \caption{This is a caption.}
    \label{test2}
\end{figure}

\end{document}

Produces:
image

Issues so are:
not displaying anymore the count of captions and not keeping the correct alignment.

Python code for examples

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.