diff --git a/.gitignore b/.gitignore
index 9c187545..a96bc0d1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,10 @@
+.idea/
+*.pyc
+dist/
+build/
+plotnn.egg-info/
+pyexamples/*.pdf
+
*.aux
*.log
*.gz
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 12f37ed3..00000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index dfea4263..00000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/plotneuralnet.iml b/.idea/plotneuralnet.iml
deleted file mode 100644
index 6f63a63c..00000000
--- a/.idea/plotneuralnet.iml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7f..00000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
deleted file mode 100644
index 9510ddec..00000000
--- a/.idea/workspace.xml
+++ /dev/null
@@ -1,110 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1536764917516
-
-
- 1536764917516
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 00000000..06ca93bc
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1 @@
+include latexnn/static/*
\ No newline at end of file
diff --git a/README.md b/README.md
index e603edaf..96f5b098 100644
--- a/README.md
+++ b/README.md
@@ -9,25 +9,28 @@ Latex code for drawing neural networks for reports and presentation. Have a look
- [ ] Add easy legend functionality
- [ ] Add more layer shapes like TruncatedPyramid, 2DSheet etc
- [ ] Add examples for RNN and likes.
+- [ ] Auto offset and size calculation
+
## Latex Usage
see examples
-## PyUsage
+## Python usage
+
+### Installation
+
+Only support Python3.
+
+ python3 setup.py install
+
+### Write NN layout
- mkdir my_project
- cd my_project
- vim my_arch.py
+The network layout looks like
- import sys
- sys.path.append('../')
- from pycore.tikzeng import *
+ from latexnn import *
- # defined your arch
- arch = [
- to_head( '..' ),
- to_cor(),
- to_begin(),
+ # defined your arch
+ arch = [
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 ),
@@ -35,17 +38,16 @@ Latex code for drawing neural networks for reports and presentation. Have a look
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' )
+ def main():
+ namefile = str(sys.argv[0]).split('.')[0]
+ to_pdf(arch, namefile + '.pdf' )
- if __name__ == '__main__':
- main()
+ if __name__ == '__main__':
+ main()
- bash ../tikzmake.sh my_arch
+Then run `python .py` to generate `.pdf` (replace `` with your file name).
## Examples
diff --git a/examples/HED/HED.tex b/examples/HED/HED.tex
index dd454754..4ff2df7b 100644
--- a/examples/HED/HED.tex
+++ b/examples/HED/HED.tex
@@ -1,6 +1,6 @@
\documentclass[border=15pt, multi, tikz]{standalone}
\usepackage{import}
-\subimport{../../layers/}{init}
+\subimport{../../static/}{init}
\usetikzlibrary{positioning}
\def\ConvColor{rgb:yellow,5;red,2.5;white,5}
diff --git a/examples/SoftmaxLoss/SoftmaxLoss.tex b/examples/SoftmaxLoss/SoftmaxLoss.tex
index c74ca20b..ccc896eb 100644
--- a/examples/SoftmaxLoss/SoftmaxLoss.tex
+++ b/examples/SoftmaxLoss/SoftmaxLoss.tex
@@ -1,6 +1,6 @@
\documentclass[border=15pt, multi, tikz]{standalone}
\usepackage{import}
-\subimport{../../layers/}{init}
+\subimport{../../static/}{init}
\usetikzlibrary{positioning}
\newcommand{\up}{0.25}
diff --git a/examples/Unet/Unet.tex b/examples/Unet/Unet.tex
index 25f366b2..4ecff6dd 100644
--- a/examples/Unet/Unet.tex
+++ b/examples/Unet/Unet.tex
@@ -1,7 +1,7 @@
\documentclass[border=8pt, multi, tikz]{standalone}
%\usepackage{blocks}
\usepackage{import}
-\subimport{../../layers/}{init}
+\subimport{../../static/}{init}
\usetikzlibrary{positioning}
\def\ConvColor{rgb:yellow,5;red,2.5;white,5}
diff --git a/examples/Unet_Ushape/Unet_ushape.tex b/examples/Unet_Ushape/Unet_ushape.tex
index 4482e271..885a3c0d 100644
--- a/examples/Unet_Ushape/Unet_ushape.tex
+++ b/examples/Unet_Ushape/Unet_ushape.tex
@@ -1,7 +1,7 @@
\documentclass[border=8pt, multi, tikz]{standalone}
%\usepackage{blocks}
\usepackage{import}
-\subimport{../../layers/}{init}
+\subimport{../../static/}{init}
\usetikzlibrary{positioning}
\def\ConvColor{rgb:yellow,5;red,2.5;white,5}
diff --git a/examples/VGG16/vgg16.tex b/examples/VGG16/vgg16.tex
index 349e4b55..5c684f9b 100644
--- a/examples/VGG16/vgg16.tex
+++ b/examples/VGG16/vgg16.tex
@@ -1,7 +1,7 @@
\documentclass[border=15pt, multi, tikz]{standalone}
%\usepackage{blocks}
\usepackage{import}
-\subimport{../../layers/}{init}
+\subimport{../../static/}{init}
\usetikzlibrary{positioning}
\def\ConvColor{rgb:yellow,5;red,2.5;white,5}
diff --git a/examples/fcn32s/fcn32.tex b/examples/fcn32s/fcn32.tex
index 7320b44d..37d77af3 100644
--- a/examples/fcn32s/fcn32.tex
+++ b/examples/fcn32s/fcn32.tex
@@ -1,6 +1,6 @@
\documentclass[border=15pt, multi, tikz]{standalone}
\usepackage{import}
-\subimport{../../layers/}{init}
+\subimport{../../static/}{init}
\usetikzlibrary{positioning}
\def\ConvColor{rgb:yellow,5;red,2.5;white,5}
diff --git a/examples/fcn8s/fcn8.tex b/examples/fcn8s/fcn8.tex
index 28b91363..ac2b34a3 100644
--- a/examples/fcn8s/fcn8.tex
+++ b/examples/fcn8s/fcn8.tex
@@ -1,6 +1,6 @@
\documentclass[border=15pt, multi, tikz]{standalone}
\usepackage{import}
-\subimport{../../layers/}{init}
+\subimport{../../static/}{init}
\usetikzlibrary{positioning}
\usetikzlibrary{3d} %for including external image
diff --git a/latexnn/__init__.py b/latexnn/__init__.py
new file mode 100644
index 00000000..3947825d
--- /dev/null
+++ b/latexnn/__init__.py
@@ -0,0 +1,3 @@
+from .tikzeng import *
+from .blocks import *
+from .layers import *
\ No newline at end of file
diff --git a/pycore/blocks.py b/latexnn/blocks.py
similarity index 99%
rename from pycore/blocks.py
rename to latexnn/blocks.py
index 82c2c2a8..5528825d 100644
--- a/pycore/blocks.py
+++ b/latexnn/blocks.py
@@ -1,5 +1,5 @@
-from .tikzeng import *
+from .layers import *
#define new block
def block_2ConvPool( name, botton, top, s_filer=256, n_filer=64, offset="(1,0,0)", size=(32,32,3.5), opacity=0.5 ):
diff --git a/latexnn/layers.py b/latexnn/layers.py
new file mode 100644
index 00000000..c61b3c39
--- /dev/null
+++ b/latexnn/layers.py
@@ -0,0 +1,165 @@
+def to_input(pathfile, to='(-3,0,0)', width=8, height=8):
+ return r"""
+\node[canvas is zy plane at x=0] (temp) at """ + to + """ {\includegraphics[width=""" + str(
+ width) + "cm" + """,height=""" + str(height) + "cm" + """]{""" + pathfile + """}};
+"""
+
+
+# Conv
+def to_Conv(name, s_filer=256, n_filer=64, offset="(0,0,0)", to="(0,0,0)", width=1, height=40, depth=40, caption=" "):
+ """
+ Create Conv layer
+ :param name: name
+ :param s_filer:
+ :param n_filer:
+ :param offset:
+ :param to:
+ :param width:
+ :param height:
+ :param depth:
+ :param caption:
+ :return:
+ """
+ return r"""
+\pic[shift={""" + offset + """}] at """ + to + """
+ {Box={
+ name=""" + name + """,
+ caption=""" + caption + r""",
+ xlabel={{""" + str(n_filer) + """, }},
+ zlabel=""" + str(s_filer) + """,
+ fill=\ConvColor,
+ height=""" + str(height) + """,
+ width=""" + str(width) + """,
+ depth=""" + str(depth) + """
+ }
+ };
+"""
+
+
+# Conv,Conv,relu
+# Bottleneck
+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={{ """ + str(n_filer[0]) + """, """ + str(n_filer[1]) + """ }},
+ zlabel=""" + str(s_filer) + """,
+ fill=\ConvColor,
+ bandfill=\ConvReluColor,
+ height=""" + str(height) + """,
+ width={ """ + str(width[0]) + """ , """ + str(width[1]) + """ },
+ depth=""" + str(depth) + """
+ }
+ };
+"""
+
+
+# Pool
+def to_Pool(name, offset="(0,0,0)", to="(0,0,0)", width=1, height=32, depth=32, opacity=0.5, caption=" "):
+ return r"""
+\pic[shift={ """ + offset + """ }] at """ + to + """
+ {Box={
+ name=""" + name + """,
+ caption=""" + caption + r""",
+ fill=\PoolColor,
+ opacity=""" + str(opacity) + """,
+ height=""" + str(height) + """,
+ width=""" + str(width) + """,
+ depth=""" + str(depth) + """
+ }
+ };
+"""
+
+
+# unpool4,
+def to_UnPool(name, offset="(0,0,0)", to="(0,0,0)", width=1, height=32, depth=32, opacity=0.5, caption=" "):
+ return r"""
+\pic[shift={ """ + offset + """ }] at """ + to + """
+ {Box={
+ name=""" + name + r""",
+ caption=""" + caption + r""",
+ fill=\UnpoolColor,
+ opacity=""" + str(opacity) + """,
+ height=""" + str(height) + """,
+ width=""" + str(width) + """,
+ depth=""" + str(depth) + """
+ }
+ };
+"""
+
+
+def to_ConvRes(name, s_filer=256, n_filer=64, offset="(0,0,0)", to="(0,0,0)", width=6, height=40, depth=40, opacity=0.2,
+ caption=" "):
+ return r"""
+\pic[shift={ """ + offset + """ }] at """ + to + """
+ {RightBandedBox={
+ name=""" + name + """,
+ caption=""" + caption + """,
+ xlabel={{ """ + str(n_filer) + """, }},
+ zlabel=""" + str(s_filer) + r""",
+ fill={rgb:white,1;black,3},
+ bandfill={rgb:white,1;black,2},
+ opacity=""" + str(opacity) + """,
+ height=""" + str(height) + """,
+ width=""" + str(width) + """,
+ depth=""" + str(depth) + """
+ }
+ };
+"""
+
+
+# ConvSoftMax
+def to_ConvSoftMax(name, s_filer=40, offset="(0,0,0)", to="(0,0,0)", width=1, height=40, depth=40, caption=" "):
+ return r"""
+\pic[shift={""" + offset + """}] at """ + to + """
+ {Box={
+ name=""" + name + """,
+ caption=""" + caption + """,
+ zlabel=""" + str(s_filer) + """,
+ fill=\SoftmaxColor,
+ height=""" + str(height) + """,
+ width=""" + str(width) + """,
+ depth=""" + str(depth) + """
+ }
+ };
+"""
+
+
+# SoftMax
+def to_SoftMax(name, s_filer=10, offset="(0,0,0)", to="(0,0,0)", width=1.5, height=3, depth=25, opacity=0.8,
+ caption=" "):
+ return r"""
+\pic[shift={""" + offset + """}] at """ + to + """
+ {Box={
+ name=""" + name + """,
+ caption=""" + caption + """,
+ xlabel={{" ","dummy"}},
+ zlabel=""" + str(s_filer) + """,
+ fill=\SoftmaxColor,
+ opacity=""" + str(opacity) + """,
+ height=""" + str(height) + """,
+ width=""" + str(width) + """,
+ depth=""" + str(depth) + """
+ }
+ };
+"""
+
+
+def to_connection(of, to):
+ return r"""
+\draw [connection] (""" + of + """-east) -- node {\midarrow} (""" + to + """-west);
+"""
+
+
+def to_skip(of, to, pos=1.25):
+ return r"""
+\path (""" + of + """-southeast) -- (""" + of + """-northeast) coordinate[pos=""" + str(pos) + """] (""" + of + """-top) ;
+\path (""" + to + """-south) -- (""" + to + """-north) coordinate[pos=1.25] (""" + to + """-top) ;
+\draw [copyconnection] (""" + of + """-northeast)
+-- node {\copymidarrow}(""" + of + """-top)
+-- node {\copymidarrow}(""" + to + """-top)
+-- node {\copymidarrow} (""" + to + """-north);
+"""
diff --git a/layers/Ball.sty b/latexnn/static/Ball.sty
similarity index 96%
rename from layers/Ball.sty
rename to latexnn/static/Ball.sty
index b5fa719f..cb37cc07 100644
--- a/layers/Ball.sty
+++ b/latexnn/static/Ball.sty
@@ -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=,
+}
diff --git a/layers/Box.sty b/latexnn/static/Box.sty
similarity index 97%
rename from layers/Box.sty
rename to latexnn/static/Box.sty
index 1d33b10e..f8f0ead8 100644
--- a/layers/Box.sty
+++ b/latexnn/static/Box.sty
@@ -1,110 +1,110 @@
-\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}
-
- %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
-
-
- \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 (\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,
- height/.store in=\cubey,
- depth/.store in=\cubez,
- scale/.store in=\scale,
- xlabel/.store in=\boxlabels,
- ylabel/.store in=\ylabel,
- zlabel/.store in=\zlabel,
- caption/.store in=\caption,
- name/.store in=\name,
- fill/.store in=\fill,
- opacity/.store in=\opacity,
- fill={rgb:red,5;green,5;blue,5;white,15},
- opacity=0.4,
- width=2,
- height=13,
- depth=15,
- scale=.2,
- xlabel={{"","","","","","","","","",""}},
- ylabel=,
- zlabel=,
- caption=,
- name=,
-}
+\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}
+
+ %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
+
+
+ \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 (\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,
+ height/.store in=\cubey,
+ depth/.store in=\cubez,
+ scale/.store in=\scale,
+ xlabel/.store in=\boxlabels,
+ ylabel/.store in=\ylabel,
+ zlabel/.store in=\zlabel,
+ caption/.store in=\caption,
+ name/.store in=\name,
+ fill/.store in=\fill,
+ opacity/.store in=\opacity,
+ fill={rgb:red,5;green,5;blue,5;white,15},
+ opacity=0.4,
+ width=2,
+ height=13,
+ depth=15,
+ scale=.2,
+ xlabel={{"","","","","","","","","",""}},
+ ylabel=,
+ zlabel=,
+ caption=,
+ name=,
+}
diff --git a/layers/RightBandedBox.sty b/latexnn/static/RightBandedBox.sty
similarity index 97%
rename from layers/RightBandedBox.sty
rename to latexnn/static/RightBandedBox.sty
index 7d74a514..1a116771 100644
--- a/layers/RightBandedBox.sty
+++ b/latexnn/static/RightBandedBox.sty
@@ -1,130 +1,130 @@
-\ProvidesPackage{RightBandedBox}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% This Block can draw simple block of boxes with custom colors.
-% Can be used for conv, deconv etc
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\tikzset{RightBandedBox/.pic={\tikzset{/block/.cd,#1}
-
- \tikzstyle{box}=[every edge/.append style={pic actions, densely dashed, opacity=.7},fill opacity=\opacity, pic actions,fill=\fill]
-
- \tikzstyle{band}=[every edge/.append style={pic actions, densely dashed, opacity=.7},fill opacity=\bandopacity, pic actions,fill=\bandfill,draw=\bandfill]
-
- \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 (art) at (\k-\x/3 , \y/2 , \z/2); %a_right_third
- \coordinate (b) at (\k-\x ,-\y/2 , \z/2);
- \coordinate (brt) at (\k-\x/3 ,-\y/2 , \z/2); %b_right_third
- \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);
- \coordinate (hrt) at (\k-\x/3 , \y/2 ,-\z/2); %h_right_third
-
- %fill box color
- \draw [box]
- (d) -- (a) -- (b) -- (c) -- cycle
- (d) -- (a) -- (h) -- (e) -- cycle;
- %dotted edges
- \draw [box]
- (f) edge (g)
- (b) edge (g)
- (h) edge (g);
- %fill band color
- \draw [band]
- (d) -- (art) -- (brt) -- (c) -- cycle
- (d) -- (art) -- (hrt) -- (e) -- cycle;
- %draw edges again which were covered by band
- \draw [box,fill opacity=0]
- (d) -- (a) -- (b) -- (c) -- cycle
- (d) -- (a) -- (h) -- (e) -- cycle;
-
- \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
- \draw [band] (d) -- (e) -- (f) -- (c) -- cycle; %East face of last box
- \draw [pic actions] (d) -- (e) -- (f) -- (c) -- cycle; %East face edges 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\zlabels"',depthlabel](f); %depth label
- \path (b1) edge ["\ylabel",midway] (a1); %height label
-
- \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 (\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);
- },
- /block/.search also={/tikz},
- /block/.cd,
- width/.store in=\cubex,
- height/.store in=\cubey,
- depth/.store in=\cubez,
- scale/.store in=\scale,
- xlabel/.store in=\boxlabels,
- ylabel/.store in=\ylabel,
- zlabel/.store in=\zlabels,
- caption/.store in=\caption,
- name/.store in=\name,
- fill/.store in=\fill,
- bandfill/.store in=\bandfill,
- opacity/.store in=\opacity,
- bandopacity/.store in=\bandopacity,
- fill={rgb:red,5;green,5;blue,5;white,15},
- bandfill={rgb:red,5;green,5;blue,5;white,5},
- opacity=0.4,
- bandopacity=0.6,
- width=2,
- height=13,
- depth=15,
- scale=.2,
- xlabel={{"","","","","","","","","",""}},
- ylabel=,
- zlabel=,
- caption=,
- name=,
-}
+\ProvidesPackage{RightBandedBox}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% This Block can draw simple block of boxes with custom colors.
+% Can be used for conv, deconv etc
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\tikzset{RightBandedBox/.pic={\tikzset{/block/.cd,#1}
+
+ \tikzstyle{box}=[every edge/.append style={pic actions, densely dashed, opacity=.7},fill opacity=\opacity, pic actions,fill=\fill]
+
+ \tikzstyle{band}=[every edge/.append style={pic actions, densely dashed, opacity=.7},fill opacity=\bandopacity, pic actions,fill=\bandfill,draw=\bandfill]
+
+ \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 (art) at (\k-\x/3 , \y/2 , \z/2); %a_right_third
+ \coordinate (b) at (\k-\x ,-\y/2 , \z/2);
+ \coordinate (brt) at (\k-\x/3 ,-\y/2 , \z/2); %b_right_third
+ \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);
+ \coordinate (hrt) at (\k-\x/3 , \y/2 ,-\z/2); %h_right_third
+
+ %fill box color
+ \draw [box]
+ (d) -- (a) -- (b) -- (c) -- cycle
+ (d) -- (a) -- (h) -- (e) -- cycle;
+ %dotted edges
+ \draw [box]
+ (f) edge (g)
+ (b) edge (g)
+ (h) edge (g);
+ %fill band color
+ \draw [band]
+ (d) -- (art) -- (brt) -- (c) -- cycle
+ (d) -- (art) -- (hrt) -- (e) -- cycle;
+ %draw edges again which were covered by band
+ \draw [box,fill opacity=0]
+ (d) -- (a) -- (b) -- (c) -- cycle
+ (d) -- (a) -- (h) -- (e) -- cycle;
+
+ \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
+ \draw [band] (d) -- (e) -- (f) -- (c) -- cycle; %East face of last box
+ \draw [pic actions] (d) -- (e) -- (f) -- (c) -- cycle; %East face edges 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\zlabels"',depthlabel](f); %depth label
+ \path (b1) edge ["\ylabel",midway] (a1); %height label
+
+ \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 (\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);
+ },
+ /block/.search also={/tikz},
+ /block/.cd,
+ width/.store in=\cubex,
+ height/.store in=\cubey,
+ depth/.store in=\cubez,
+ scale/.store in=\scale,
+ xlabel/.store in=\boxlabels,
+ ylabel/.store in=\ylabel,
+ zlabel/.store in=\zlabels,
+ caption/.store in=\caption,
+ name/.store in=\name,
+ fill/.store in=\fill,
+ bandfill/.store in=\bandfill,
+ opacity/.store in=\opacity,
+ bandopacity/.store in=\bandopacity,
+ fill={rgb:red,5;green,5;blue,5;white,15},
+ bandfill={rgb:red,5;green,5;blue,5;white,5},
+ opacity=0.4,
+ bandopacity=0.6,
+ width=2,
+ height=13,
+ depth=15,
+ scale=.2,
+ xlabel={{"","","","","","","","","",""}},
+ ylabel=,
+ zlabel=,
+ caption=,
+ name=,
+}
diff --git a/layers/init.tex b/latexnn/static/init.tex
similarity index 96%
rename from layers/init.tex
rename to latexnn/static/init.tex
index 9a9b3eb0..b1d5b959 100644
--- a/layers/init.tex
+++ b/latexnn/static/init.tex
@@ -1,11 +1,11 @@
-%\ProvidesPackage{init}
-\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.8mm,draw=\edgecolor] (-0.3,0) -- ++(0.3,0);}
-
-\usepackage{Ball}
-\usepackage{Box}
-\usepackage{RightBandedBox}
-
+%\ProvidesPackage{init}
+\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.8mm,draw=\edgecolor] (-0.3,0) -- ++(0.3,0);}
+
+\usepackage{Ball}
+\usepackage{Box}
+\usepackage{RightBandedBox}
+
diff --git a/latexnn/tikzeng.py b/latexnn/tikzeng.py
new file mode 100644
index 00000000..913accc4
--- /dev/null
+++ b/latexnn/tikzeng.py
@@ -0,0 +1,67 @@
+import os
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+def to_head():
+ pathlayers = os.path.join(os.path.dirname(__file__), 'static', '')
+ return r"""
+\documentclass[border=8pt, multi, tikz]{standalone}
+\usepackage{import}
+\subimport{""" + pathlayers + r"""}{init}
+\usetikzlibrary{positioning}
+\usetikzlibrary{3d} %for including external image
+"""
+
+
+def to_cor():
+ return r"""
+\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 to_begin():
+ return r"""
+\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]
+"""
+
+
+def to_end():
+ return r"""
+\end{tikzpicture}
+\end{document}
+"""
+
+
+def to_generate(arch, pathname="file.tex"):
+ final_arch = [to_head(), to_cor(), to_begin()]
+ final_arch.extend(arch)
+ final_arch.append(to_end())
+ with open(pathname, "w") as f:
+ logger.info("Print architecture")
+ for c in final_arch:
+ if logger.getEffectiveLevel() < logging.WARNING:
+ print(c)
+ f.write(c)
+ logger.critical("Run following command:\npdflatex {0}.tex && rm -f {0}.aux {0}.log {0}.vscodeLog {0}.tex".format(
+ ".".join(pathname.split(".")[:-1])))
+
+
+def to_pdf(arch, pathname="file.pdf"):
+ target = ".".join(pathname.split(".")[:-1])
+ tex = target + ".tex"
+ to_generate(arch, tex)
+ os.system("pdflatex %s" % tex)
+ os.system("rm -rf {0}.aux {0}.log {0}.vscodeLog {0}.tex".format(target))
diff --git a/pycore/__init__.py b/pycore/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/pycore/__init__.pyc b/pycore/__init__.pyc
deleted file mode 100644
index e9f05b6d..00000000
Binary files a/pycore/__init__.pyc and /dev/null differ
diff --git a/pycore/tikzeng.py b/pycore/tikzeng.py
deleted file mode 100644
index 17df4df1..00000000
--- a/pycore/tikzeng.py
+++ /dev/null
@@ -1,197 +0,0 @@
-
-import os
-
-def to_head( projectpath ):
- pathlayers = os.path.join( projectpath, 'layers/' )
- return r"""
-\documentclass[border=8pt, multi, tikz]{standalone}
-\usepackage{import}
-\subimport{"""+ pathlayers + r"""}{init}
-\usetikzlibrary{positioning}
-\usetikzlibrary{3d} %for including external image
-"""
-
-def to_cor():
- return r"""
-\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 to_begin():
- return r"""
-\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]
-"""
-
-# layers definition
-
-def to_input( pathfile, to='(-3,0,0)', width=8, height=8 ):
- return r"""
-\node[canvas is zy plane at x=0] (temp) at """+ to +""" {\includegraphics[width="""+ str(width)+"cm"+""",height="""+ str(height)+"cm"+"""]{"""+ pathfile +"""}};
-"""
-
-# Conv
-def to_Conv( name, s_filer=256, n_filer=64, offset="(0,0,0)", to="(0,0,0)", width=1, height=40, depth=40, caption=" " ):
- return r"""
-\pic[shift={"""+ offset +"""}] at """+ to +"""
- {Box={
- name=""" + name +""",
- caption="""+ caption +r""",
- xlabel={{"""+ str(n_filer) +""", }},
- zlabel="""+ str(s_filer) +""",
- fill=\ConvColor,
- height="""+ str(height) +""",
- width="""+ str(width) +""",
- depth="""+ str(depth) +"""
- }
- };
-"""
-
-# Conv,Conv,relu
-# Bottleneck
-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={{ """+ str(n_filer[0]) +""", """+ str(n_filer[1]) +""" }},
- zlabel="""+ str(s_filer) +""",
- fill=\ConvColor,
- bandfill=\ConvReluColor,
- height="""+ str(height) +""",
- width={ """+ str(width[0]) +""" , """+ str(width[1]) +""" },
- depth="""+ str(depth) +"""
- }
- };
-"""
-
-
-
-# Pool
-def to_Pool(name, offset="(0,0,0)", to="(0,0,0)", width=1, height=32, depth=32, opacity=0.5, caption=" "):
- return r"""
-\pic[shift={ """+ offset +""" }] at """+ to +"""
- {Box={
- name="""+name+""",
- caption="""+ caption +r""",
- fill=\PoolColor,
- opacity="""+ str(opacity) +""",
- height="""+ str(height) +""",
- width="""+ str(width) +""",
- depth="""+ str(depth) +"""
- }
- };
-"""
-
-# unpool4,
-def to_UnPool(name, offset="(0,0,0)", to="(0,0,0)", width=1, height=32, depth=32, opacity=0.5, caption=" "):
- return r"""
-\pic[shift={ """+ offset +""" }] at """+ to +"""
- {Box={
- name="""+ name +r""",
- caption="""+ caption +r""",
- fill=\UnpoolColor,
- opacity="""+ str(opacity) +""",
- height="""+ str(height) +""",
- width="""+ str(width) +""",
- depth="""+ str(depth) +"""
- }
- };
-"""
-
-
-
-def to_ConvRes( name, s_filer=256, n_filer=64, offset="(0,0,0)", to="(0,0,0)", width=6, height=40, depth=40, opacity=0.2, caption=" " ):
- return r"""
-\pic[shift={ """+ offset +""" }] at """+ to +"""
- {RightBandedBox={
- name="""+ name + """,
- caption="""+ caption + """,
- xlabel={{ """+ str(n_filer) + """, }},
- zlabel="""+ str(s_filer) +r""",
- fill={rgb:white,1;black,3},
- bandfill={rgb:white,1;black,2},
- opacity="""+ str(opacity) +""",
- height="""+ str(height) +""",
- width="""+ str(width) +""",
- depth="""+ str(depth) +"""
- }
- };
-"""
-
-
-# ConvSoftMax
-def to_ConvSoftMax( name, s_filer=40, offset="(0,0,0)", to="(0,0,0)", width=1, height=40, depth=40, caption=" " ):
- return r"""
-\pic[shift={"""+ offset +"""}] at """+ to +"""
- {Box={
- name=""" + name +""",
- caption="""+ caption +""",
- zlabel="""+ str(s_filer) +""",
- fill=\SoftmaxColor,
- height="""+ str(height) +""",
- width="""+ str(width) +""",
- depth="""+ str(depth) +"""
- }
- };
-"""
-
-# SoftMax
-def to_SoftMax( name, s_filer=10, offset="(0,0,0)", to="(0,0,0)", width=1.5, height=3, depth=25, opacity=0.8, caption=" " ):
- return r"""
-\pic[shift={"""+ offset +"""}] at """+ to +"""
- {Box={
- name=""" + name +""",
- caption="""+ caption +""",
- xlabel={{" ","dummy"}},
- zlabel="""+ str(s_filer) +""",
- fill=\SoftmaxColor,
- opacity="""+ str(opacity) +""",
- height="""+ str(height) +""",
- width="""+ str(width) +""",
- depth="""+ str(depth) +"""
- }
- };
-"""
-
-
-def to_connection( of, to):
- return r"""
-\draw [connection] ("""+of+"""-east) -- node {\midarrow} ("""+to+"""-west);
-"""
-
-def to_skip( of, to, pos=1.25):
- return r"""
-\path ("""+ of +"""-southeast) -- ("""+ of +"""-northeast) coordinate[pos="""+ str(pos) +"""] ("""+ of +"""-top) ;
-\path ("""+ to +"""-south) -- ("""+ to +"""-north) coordinate[pos=1.25] ("""+ to +"""-top) ;
-\draw [copyconnection] ("""+of+"""-northeast)
--- node {\copymidarrow}("""+of+"""-top)
--- node {\copymidarrow}("""+to+"""-top)
--- node {\copymidarrow} ("""+to+"""-north);
-"""
-
-def to_end():
- return r"""
-\end{tikzpicture}
-\end{document}
-"""
-
-
-def to_generate( arch, pathname="file.tex" ):
- with open(pathname, "w") as f:
- for c in arch:
- print(c)
- f.write( c )
-
-
-
diff --git a/pycore/tikzeng.pyc b/pycore/tikzeng.pyc
deleted file mode 100644
index ed1ff6e9..00000000
Binary files a/pycore/tikzeng.pyc and /dev/null differ
diff --git a/pyexamples/test_simple.py b/pyexamples/test_simple.py
index e90b0a11..86191e67 100644
--- a/pyexamples/test_simple.py
+++ b/pyexamples/test_simple.py
@@ -1,13 +1,8 @@
-
import sys
-sys.path.append('../')
-from pycore.tikzeng import *
+from latexnn 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 ),
@@ -15,12 +10,11 @@
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' )
+ to_pdf(arch, namefile + '.pdf' )
if __name__ == '__main__':
main()
diff --git a/pyexamples/unet.py b/pyexamples/unet.py
index 25ddd3f4..077c6499 100644
--- a/pyexamples/unet.py
+++ b/pyexamples/unet.py
@@ -1,16 +1,9 @@
-
import sys
-sys.path.append('../')
-from pycore.tikzeng import *
-from pycore.blocks import *
+from latexnn import *
arch = [
- to_head('..'),
- to_cor(),
- to_begin(),
-
#input
- to_input( '../examples/fcn8s/cats.jpg' ),
+ to_input('../examples/fcn8s/cats.jpg'),
#block-001
to_ConvConvRelu( name='ccr_b1', s_filer=500, n_filer=(64,64), offset="(0,0,0)", to="(0,0,0)", width=(2,2), height=40, depth=40 ),
@@ -37,15 +30,13 @@
to_skip( of='ccr_b1', to='ccr_res_b9', pos=1.25),
to_ConvSoftMax( name="soft1", s_filer=512, offset="(0.75,0,0)", to="(end_b9-east)", width=1, height=40, depth=40, caption="SOFT" ),
- to_connection( "end_b9", "soft1"),
-
- to_end()
+ to_connection( "end_b9", "soft1")
]
def main():
namefile = str(sys.argv[0]).split('.')[0]
- to_generate(arch, namefile + '.tex' )
+ to_pdf(arch, namefile + '.pdf' )
if __name__ == '__main__':
main()
diff --git a/setup.py b/setup.py
new file mode 100644
index 00000000..e9ee55b7
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,134 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Setup file adopted from https://github.com/kennethreitz/setup.py
+
+# Note: To use the 'upload' functionality of this file, you must:
+# $ pip install twine
+
+import io
+import os
+import sys
+from shutil import rmtree
+
+from setuptools import find_packages, setup, Command
+
+# Package meta-data.
+NAME = 'latexnn'
+DESCRIPTION = 'PlotNeuralNet forked from https://github.com/HarisIqbal88/PlotNeuralNet'
+URL = 'https://github.com/jiayiliu/PlotNeuralNet'
+EMAIL = 'xxx@xxx'
+AUTHOR = 'HarisIqbal88,jiayiliu'
+REQUIRES_PYTHON = '>=3.6.0'
+VERSION = "0.1dev0"
+
+# What packages are required for this module to be executed?
+REQUIRED = [
+ # 'requests', 'maya', 'records',
+]
+
+# What packages are optional?
+EXTRAS = {
+ # 'fancy feature': ['django'],
+}
+
+# The rest you shouldn't have to touch too much :)
+# ------------------------------------------------
+# Except, perhaps the License and Trove Classifiers!
+# If you do change the License, remember to change the Trove Classifier for that!
+
+here = os.path.abspath(os.path.dirname(__file__))
+
+# Import the README and use it as the long-description.
+# Note: this will only work if 'README.md' is present in your MANIFEST.in file!
+try:
+ with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
+ long_description = '\n' + f.read()
+except FileNotFoundError:
+ long_description = DESCRIPTION
+
+# Load the package's __version__.py module as a dictionary.
+about = {}
+if not VERSION:
+ project_slug = NAME.lower().replace("-", "_").replace(" ", "_")
+ with open(os.path.join(here, project_slug, '__version__.py')) as f:
+ exec(f.read(), about)
+else:
+ about['__version__'] = VERSION
+
+
+class UploadCommand(Command):
+ """Support setup.py upload."""
+
+ description = 'Build and publish the package.'
+ user_options = []
+
+ @staticmethod
+ def status(s):
+ """Prints things in bold."""
+ print('\033[1m{0}\033[0m'.format(s))
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ try:
+ self.status('Removing previous builds…')
+ rmtree(os.path.join(here, 'dist'))
+ except OSError:
+ pass
+
+ self.status('Building Source and Wheel (universal) distribution…')
+ os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable))
+
+ self.status('Uploading the package to PyPI via Twine…')
+ os.system('twine upload dist/*')
+
+ self.status('Pushing git tags…')
+ os.system('git tag v{0}'.format(about['__version__']))
+ os.system('git push --tags')
+
+ sys.exit()
+
+
+# Where the magic happens:
+setup(
+ name=NAME,
+ version=about['__version__'],
+ description=DESCRIPTION,
+ long_description=long_description,
+ long_description_content_type='text/markdown',
+ author=AUTHOR,
+ author_email=EMAIL,
+ python_requires=REQUIRES_PYTHON,
+ url=URL,
+ packages=find_packages(include=('latexnn',)),
+ # If your package is a single module, use this instead of 'packages':
+ # py_modules=['latexnn'],
+
+ # entry_points={
+ # 'console_scripts': ['mycli=mymodule:cli'],
+ # },
+ install_requires=REQUIRED,
+ extras_require=EXTRAS,
+ include_package_data=True,
+ license='MIT',
+ classifiers=[
+ # Trove classifiers
+ # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
+ 'License :: OSI Approved :: MIT License',
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.6',
+ 'Programming Language :: Python :: Implementation :: CPython',
+ 'Programming Language :: Python :: Implementation :: PyPy'
+ ],
+ # $ setup.py publish support.
+ cmdclass={
+ 'upload': UploadCommand,
+ },
+ zip_safe=False
+)
\ No newline at end of file