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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
build
*.egg-info
*.pyc
dist

*.aux
*.log
*.gz
Expand Down Expand Up @@ -82,4 +87,4 @@ venv.bak/
/site

# mypy
.mypy_cache/
.mypy_cache/
11 changes: 11 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "HarisIqbal88"
given-names: ""
orcid: ""
title: "PlotNeuralNet"
version: 1.0.0
doi: "10.5281/zenodo.2526396"
date-released: 2018-12-25
url: "https://github.com/HarisIqbal88/PlotNeuralNet/tree/v1.0.0"
5 changes: 5 additions & 0 deletions PlotNeuralNetPy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from . import pycore
from . import pyexamples
from .__version__ import __version__
2 changes: 2 additions & 0 deletions PlotNeuralNetPy/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__version__ = "1.0.0"

4 changes: 4 additions & 0 deletions PlotNeuralNetPy/pycore/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from .blocks import block_2ConvPool, block_Unconv, block_Res
from .tikzeng import *
File renamed without changes.
3 changes: 2 additions & 1 deletion pycore/tikzeng.py → PlotNeuralNetPy/pycore/tikzeng.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import os
from pathlib import Path

def to_head( projectpath ):
def to_head( projectpath=Path(__file__).parent.parent ):
pathlayers = os.path.join( projectpath, 'layers/' ).replace('\\', '/')
return r"""
\documentclass[border=8pt, multi, tikz]{standalone}
Expand Down
4 changes: 4 additions & 0 deletions PlotNeuralNetPy/pyexamples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from .test_simple import main, arch
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports conflict. No need to import the individual example namespaces into the top __init__ namespace.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Didn't catch that!

from .unet import main, arch
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

import sys
sys.path.append('../')
from pycore.tikzeng import *
from ..pycore.tikzeng import *

# defined your arch
arch = [
to_head( '..' ),
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 ),
Expand Down
105 changes: 105 additions & 0 deletions PlotNeuralNetPy/pyexamples/test_simple.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@

\documentclass[border=8pt, multi, tikz]{standalone}
\usepackage{import}
\subimport{C:/Users/jonas/code/PlotNeuralNet/PlotNeuralNetPy/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}
\def\SumColor{rgb:blue,5;green,15}

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

\pic[shift={(1.5,0,0)}] at (soft1-east)
{Ball={
name=sum1,
fill=\SumColor,
opacity=0.6,
radius=2.5,
logo=$+$
}
};

\draw [connection] (soft1-east) -- node {\midarrow} (sum1-west);

\end{tikzpicture}
\end{document}
7 changes: 3 additions & 4 deletions pyexamples/unet.py → PlotNeuralNetPy/pyexamples/unet.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

import sys
sys.path.append('../')
from pycore.tikzeng import *
from pycore.blocks import *
from ..pycore.tikzeng import *
from ..pycore.blocks import *

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

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Base on this [website](https://gist.github.com/rain1024/98dd5e2c6c8c28f9ea9d), p
cd pyexamples/
bash ../tikzmake.sh test_simple
```

3. Optional: Installing the python interface as python module (this makes `import PlotNeuralNetPy` possible).
```
python -m pip install --use-feature=in-tree-build path/to/PlotNeuralNet
```

## TODO

Expand Down
80 changes: 40 additions & 40 deletions layers/Ball.sty
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
\ProvidesPackage{Ball}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This Block can draw small Ball
%Elementwise or reduction operations can be drawn with this
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{Ball/.pic={\tikzset{/sphere/.cd,#1}
\pgfmathsetmacro{\r}{\radius*\scale}
\shade[ball color=\fill,opacity=\opacity] (0,0,0) circle (\r);
\draw (0,0,0) circle [radius=\r] node[scale=4*\r] {\logo};
\coordinate (\name-anchor) at ( 0 , 0 , 0) ;
\coordinate (\name-east) at ( \r, 0 , 0) ;
\coordinate (\name-west) at (-\r, 0 , 0) ;
\coordinate (\name-north) at ( 0 , \r , 0) ;
\coordinate (\name-south) at ( 0 , -\r, 0) ;
\path (\name-south) + (0,-20pt) coordinate (caption-node)
edge ["\textcolor{black}{\bf \caption}"'] (caption-node); %Ball caption
},
/sphere/.search also={/tikz},
/sphere/.cd,
radius/.store in=\radius,
scale/.store in=\scale,
caption/.store in=\caption,
name/.store in=\name,
fill/.store in=\fill,
logo/.store in=\logo,
opacity/.store in=\opacity,
logo=$\Sigma$,
fill=green,
opacity=0.10,
scale=0.2,
radius=0.5,
caption=,
name=,
}
\ProvidesPackage{Ball}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This Block can draw small Ball
%Elementwise or reduction operations can be drawn with this
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\tikzset{Ball/.pic={\tikzset{/sphere/.cd,#1}

\pgfmathsetmacro{\r}{\radius*\scale}

\shade[ball color=\fill,opacity=\opacity] (0,0,0) circle (\r);
\draw (0,0,0) circle [radius=\r] node[scale=4*\r] {\logo};

\coordinate (\name-anchor) at ( 0 , 0 , 0) ;
\coordinate (\name-east) at ( \r, 0 , 0) ;
\coordinate (\name-west) at (-\r, 0 , 0) ;
\coordinate (\name-north) at ( 0 , \r , 0) ;
\coordinate (\name-south) at ( 0 , -\r, 0) ;

\path (\name-south) + (0,-20pt) coordinate (caption-node)
edge ["\textcolor{black}{\bf \caption}"'] (caption-node); %Ball caption

},
/sphere/.search also={/tikz},
/sphere/.cd,
radius/.store in=\radius,
scale/.store in=\scale,
caption/.store in=\caption,
name/.store in=\name,
fill/.store in=\fill,
logo/.store in=\logo,
opacity/.store in=\opacity,
logo=$\Sigma$,
fill=green,
opacity=0.10,
scale=0.2,
radius=0.5,
caption=,
name=,
}
Loading