Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
25 changes: 7 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# PlotNeuralNet
# Plot Neural Net
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2526396.svg)](https://doi.org/10.5281/zenodo.2526396)

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.
LaTeX code for drawing neural networks for reports and presentations. Take a look at the examples to see how they are made. Additionally, let's consolidate any improvements you make and fix any bugs to help more people with this code.

## Examples

Expand All @@ -19,38 +19,27 @@ Following are some network representations:
<h6 align="center">Holistically-Nested Edge Detection (<a href="https://www.overleaf.com/read/jxhnkcnwhfxp">view on Overleaf</a>)</h6>

## Getting Started
1. Install the following packages on Ubuntu.
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](https://gist.github.com/rain1024/98dd5e2c6c8c28f9ea9d), please install the following packages.
* Ubuntu 18.04.
```
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
sudo apt-get install texlive-latex-base texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra
```

* Windows
1. Download and install [MikTeX](https://miktex.org/download).
2. Download and install bash runner on Windows, recommends [Git bash](https://git-scm.com/download/win) or Cygwin(https://www.cygwin.com/)

2. Execute the example as followed.
2. **Execute the example as following.**
```
cd pyexamples/
bash ../tikzmake.sh test_simple
```

## TODO

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


## Latex usage

See [`examples`](examples) directory for usage.
Expand Down
150 changes: 71 additions & 79 deletions layers/Box.sty
Original file line number Diff line number Diff line change
@@ -1,88 +1,80 @@
\ProvidesPackage{Box}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This Block can draw simple block of boxes with custom colors.
% Can be used for conv, deconv etc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{Box/.pic={\tikzset{/boxblock/.cd,#1}
\tikzstyle{box}=[every edge/.append style={pic actions, densely dashed, opacity=.7},fill opacity=\opacity, pic actions,fill=\fill]
\pgfmathsetmacro{\y}{\cubey*\scale}
\pgfmathsetmacro{\z}{\cubez*\scale}
\tikzstyle{box}=[every edge/.append style={pic actions, densely dashed, opacity=.7},fill opacity=\opacity, pic actions,fill=\fill]

\pgfmathsetmacro{\y}{\cubey*\scale}
\pgfmathsetmacro{\z}{\cubez*\scale}

%Multiple concatenated boxes
\foreach[count=\i,%
evaluate=\i as \xlabel using {array({\boxlabels},\i-1)},%
evaluate=\unscaledx as \k using {\unscaledx*\scale+\prev}, remember=\k as \prev (initially 0)]
\unscaledx in \cubex
{
\pgfmathsetmacro{\x}{\unscaledx*\scale}
\coordinate (a) at (\k-\x , \y/2 , \z/2);
\coordinate (b) at (\k-\x ,-\y/2 , \z/2);
\coordinate (c) at (\k ,-\y/2 , \z/2);
\coordinate (d) at (\k , \y/2 , \z/2);
\coordinate (e) at (\k , \y/2 ,-\z/2);
\coordinate (f) at (\k ,-\y/2 ,-\z/2);
\coordinate (g) at (\k-\x ,-\y/2 ,-\z/2);
\coordinate (h) at (\k-\x , \y/2 ,-\z/2);

\draw [box]
(d) -- (a) -- (b) -- (c) -- cycle
(d) -- (a) -- (h) -- (e) -- cycle
%dotted edges
(f) edge (g)
(b) edge (g)
(h) edge (g)
;
\path (b) edge ["\xlabel"',midway] (c);

\xdef\LastEastx{\k} %\k persists as \LastEastx after loop
}%Loop ends
\draw [box] (d) -- (e) -- (f) -- (c) -- cycle; %East face of last box

\coordinate (a1) at (0 , \y/2 , \z/2);
\coordinate (b1) at (0 ,-\y/2 , \z/2);
\tikzstyle{depthlabel}=[pos=0,text width=14*\z,text centered,sloped]

\path (c) edge ["\small\zlabel"',depthlabel](f); %depth label
\path (b1) edge ["\ylabel",midway] (a1); %height label

\foreach[count=\i,
evaluate=\i as \xlabel using {array({\boxlabels},\i-1)},
evaluate=\unscaledx as \k using {\unscaledx*\scale+\prev}, remember=\k as \prev (initially 0)
]
\unscaledx in \cubex
{
\pgfmathsetmacro{\x}{\unscaledx*\scale}
\coordinate (a) at (\k-\x , \y/2 , \z/2);
\coordinate (b) at (\k-\x ,-\y/2 , \z/2);
\coordinate (c) at (\k ,-\y/2 , \z/2);
\coordinate (d) at (\k , \y/2 , \z/2);
\coordinate (e) at (\k , \y/2 ,-\z/2);
\coordinate (f) at (\k ,-\y/2 ,-\z/2);
\coordinate (g) at (\k-\x ,-\y/2 ,-\z/2);
\coordinate (h) at (\k-\x , \y/2 ,-\z/2);

\draw [box]
(d) -- (a) -- (b) -- (c) -- cycle
(d) -- (a) -- (h) -- (e) -- cycle
(f) edge (g)
(b) edge (g)
(h) edge (g)
;
\path (b) edge ["\small\xlabel"',midway] (c);
\xdef\LastEastx{\k}
}
\draw [box] (d) -- (e) -- (f) -- (c) -- cycle;

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

%Define nodes to be used outside on the pic object
\coordinate (\name-west) at (0,0,0) ;
\coordinate (\name-east) at (\LastEastx, 0,0) ;
\coordinate (\name-north) at (\LastEastx/2,\y/2,0);
\coordinate (\name-south) at (\LastEastx/2,-\y/2,0);
\coordinate (\name-anchor) at (\LastEastx/2, 0,0) ;

\coordinate (\name-near) at (\LastEastx/2,0,\z/2);
\coordinate (\name-far) at (\LastEastx/2,0,-\z/2);

\coordinate (\name-nearwest) at (0,0,\z/2);
\coordinate (\name-neareast) at (\LastEastx,0,\z/2);
\coordinate (\name-farwest) at (0,0,-\z/2);
\coordinate (\name-fareast) at (\LastEastx,0,-\z/2);

\coordinate (\name-northeast) at (\name-north-|\name-east);
\coordinate (\name-northwest) at (\name-north-|\name-west);
\coordinate (\name-southeast) at (\name-south-|\name-east);
\coordinate (\name-southwest) at (\name-south-|\name-west);

\coordinate (\name-nearnortheast) at (\LastEastx, \y/2, \z/2);
\coordinate (\name-farnortheast) at (\LastEastx, \y/2,-\z/2);
\coordinate (\name-nearsoutheast) at (\LastEastx,-\y/2, \z/2);
\coordinate (\name-farsoutheast) at (\LastEastx,-\y/2,-\z/2);
\coordinate (a1) at (0 , \y/2 , \z/2);
\coordinate (b1) at (0 ,-\y/2 , \z/2);

\tikzstyle{depthlabel}=[pos=0.5,text width=14*\z,text centered,sloped]
\path (c) edge ["\small\zlabel"',depthlabel](f);
\path (b1) edge ["\small\ylabel",midway] (a1);


\tikzstyle{captionlabel}=[text width=15*\LastEastx/\scale,text centered]
\path (\LastEastx/2,-\y/2,+\z/2) + (0,-25pt) coordinate (cap)
edge ["\textcolor{black}{ \bf \caption}"',captionlabel](cap);

\coordinate (\name-nearnorthwest) at (0, \y/2, \z/2);
\coordinate (\name-farnorthwest) at (0, \y/2,-\z/2);
\coordinate (\name-nearsouthwest) at (0,-\y/2, \z/2);
\coordinate (\name-farsouthwest) at (0,-\y/2,-\z/2);
\coordinate (\name-west) at (0,0,0) ;
\coordinate (\name-east) at (\LastEastx, 0,0) ;
\coordinate (\name-north) at (\LastEastx/2,\y/2,0);
\coordinate (\name-south) at (\LastEastx/2,-\y/2,0);
\coordinate (\name-anchor) at (\LastEastx/2, 0,0) ;

\coordinate (\name-near) at (\LastEastx/2,0,\z/2);
\coordinate (\name-far) at (\LastEastx/2,0,-\z/2);

\coordinate (\name-nearwest) at (0,0,\z/2);
\coordinate (\name-neareast) at (\LastEastx,0,\z/2);
\coordinate (\name-farwest) at (0,0,-\z/2);
\coordinate (\name-fareast) at (\LastEastx,0,-\z/2);

\coordinate (\name-northeast) at (\name-north-|\name-east);
\coordinate (\name-northwest) at (\name-north-|\name-west);
\coordinate (\name-southeast) at (\name-south-|\name-east);
\coordinate (\name-southwest) at (\name-south-|\name-west);

\coordinate (\name-nearnortheast) at (\LastEastx, \y/2, \z/2);
\coordinate (\name-farnortheast) at (\LastEastx, \y/2,-\z/2);
\coordinate (\name-nearsoutheast) at (\LastEastx,-\y/2, \z/2);
\coordinate (\name-farsoutheast) at (\LastEastx,-\y/2,-\z/2);

\coordinate (\name-nearnorthwest) at (0, \y/2, \z/2);
\coordinate (\name-farnorthwest) at (0, \y/2,-\z/2);
\coordinate (\name-nearsouthwest) at (0,-\y/2, \z/2);
\coordinate (\name-farsouthwest) at (0,-\y/2,-\z/2);

},
},
/boxblock/.search also={/tikz},
/boxblock/.cd,
width/.store in=\cubex,
Expand Down
9 changes: 9 additions & 0 deletions layers/NeuralPlot.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\usetikzlibrary{quotes,arrows.meta}
\usetikzlibrary{positioning}

\def\edgecolor{rgb:blue,4;red,1;green,4;black,3}
\newcommand{\midarrow}{\tikz \draw[-Stealth,line width=0.5mm,draw=\edgecolor] (-0.3,0) -- ++(0.3,0);}

\usepackage{Ball}
\usepackage{Box}
\usepackage{RightBandedBox}
Loading