diff --git a/Deep4-net/Deep4-net.pdf b/Deep4-net/Deep4-net.pdf new file mode 100644 index 00000000..4ec2fb95 Binary files /dev/null and b/Deep4-net/Deep4-net.pdf differ diff --git a/Deep4-net/Deep4-net.py b/Deep4-net/Deep4-net.py new file mode 100644 index 00000000..4b3b2d2a --- /dev/null +++ b/Deep4-net/Deep4-net.py @@ -0,0 +1,61 @@ +import sys +sys.path.append('../') +from pycore.tikzeng import * + +# defined your arch +arch = [ + + to_head( '..' ), + to_cor(), + to_begin(), + + to_input('input',name='InputData'), + + # to_Conv("conv1", 4, 1, offset="(0,0,0)", to="(0,0,0)", height=80, depth=22, width=1 ), + # to_Conv("conv2", 4, 4, offset="(1,0,0)", to="(conv1-east)", height=80, depth=22, width=1 ), + to_ConvConvRelu( "conv1", s_filer=4, n_filer=(1,4), offset="(0,0,0)", to="(1,0,0)", width=(3,4), height=40, depth=40, caption="ConvBlock1"), + #to_connection( "InputData", "conv1"), + to_BN("bn1", offset="(0.4,0,1.5)", to="(conv1-east)",height=25, depth=20, width=2,caption="BatchNorm1" ), + to_Pool("pool1", offset="(1.5,0,1)", to="(bn1-east)",height=40, depth=20, width=1,caption="MaxPool1" ), #2x1 + to_connection( "bn1", "pool1"), + + to_ConvConvRelu( "conv2", s_filer=8, n_filer=(4,8), offset="(2.5,0,0)", to="(pool1-east)", width=(3,4), height=40, depth=38, caption="ConvBlock2"), + to_BN("bn2", offset="(0.4,0,1.5)", to="(conv2-east)",height=25, depth=20, width=2,caption="BatchNorm2" ), + to_Pool("pool2", offset="(1.5,0,1)", to="(bn2-east)",height=40, depth=20, width=1,caption="MaxPool2" ), #2x1 + to_connection( "pool1", "conv2"), + to_connection( "bn2", "pool2"), + + to_ConvConvRelu( "conv3", s_filer=16, n_filer=(8,16), offset="(2.5,0,0)", to="(pool2-east)", width=(3,4), height=40, depth=36, caption="ConvBlock3"), + to_BN("bn3", offset="(0.4,0,1.5)", to="(conv3-east)",height=25, depth=20, width=2,caption="BatchNorm3" ), + to_Pool("pool3", offset="(1.5,0,1)", to="(bn3-east)",height=40, depth=25, width=1,caption="MaxPool3" ), #2x2 + to_connection( "pool2", "conv3"), + to_connection( "bn3", "pool3"), + + to_ConvConvRelu( "conv4", s_filer=32, n_filer=(16,32), offset="(2.5,0,0)", to="(pool3-east)", width=(3,4), height=37, depth=34, caption="ConvBlock4"), + to_BN("bn4", offset="(0.4,0,1.5)", to="(conv4-east)",height=25, depth=20, width=2,caption="BatchNorm4" ), + to_Pool("pool4", offset="(1.5,0,0.4)", to="(bn4-east)",height=40, depth=25, width=1,caption="MaxPool4" ), #2x2 + to_connection( "pool3", "conv4"), + to_connection( "bn4", "pool4"), + + to_ConvConvRelu( "conv5", s_filer=64, n_filer=(32,64), offset="(2.5,0,0)", to="(pool4-east)", width=(3,4), height=34, depth=30, caption="ConvBlock5"), + to_BN("bn5", offset="(0.5,0.6,1.5)", to="(conv5-east)",height=25, depth=20, width=2,caption="BatchNorm5" ), + to_Pool("pool5", offset="(1.5,0,1)", to="(bn5-east)",height=40, depth=25, width=1,caption="MaxPool5" ), #2x2 + to_connection( "pool4", "conv5"), + to_connection( "bn5", "pool5"), + + to_FulCon("fc1", 256, 128, offset="(8,0,3)", to="(pool5-east)", height=3, depth=30, width=3,caption='FC1'), + to_FulCon("fc2", 512, 256, offset="(1,0,0)", to="(fc1-east)", height=3, depth=30, width=3,caption='FC2'), + to_connection("pool5","fc1"), + + to_SoftMax( "SoftMaX", s_filer=2, offset="(3,0,0)", to="(fc2-east)", width=1.5, height=25, depth=40, opacity=0.8, caption="SoftMaX" ), + to_connection("fc2","SoftMaX"), + + to_end() + ] + +def main(): + namefile = str(sys.argv[0]).split('.')[0] + to_generate(arch, namefile + '.tex' ) + +if __name__ == '__main__': + main() diff --git a/Deep4-net/input.png b/Deep4-net/input.png new file mode 100644 index 00000000..98f34cd5 Binary files /dev/null and b/Deep4-net/input.png differ diff --git a/README.md b/README.md index a3edec89..37d1ac16 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,14 @@ Base on this [website](https://gist.github.com/rain1024/98dd5e2c6c8c28f9ea9d), p - [ ] Add more layer shapes like TruncatedPyramid, 2DSheet etc - [ ] Add examples for RNN and likes. +## ADD by ME --modified + +- [X] to_BN() batch norm with brown color + +- [X] to_FulCon() fully connected layer with blue + +check [`Deep4-net`](Deep4-net) + ## Latex usage See [`examples`](examples) directory for usage. diff --git a/pycore/__init__.pyc b/pycore/__init__.pyc index e9f05b6d..8a2dfd7e 100644 Binary files a/pycore/__init__.pyc and b/pycore/__init__.pyc differ diff --git a/pycore/tikzeng.py b/pycore/tikzeng.py index f29e1205..5b1733b8 100644 --- a/pycore/tikzeng.py +++ b/pycore/tikzeng.py @@ -18,6 +18,7 @@ def to_cor(): \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\BatchNcolor{rgb:blue,19;green,69;red,139} \def\FcReluColor{rgb:blue,5;red,5;white,4} \def\SoftmaxColor{rgb:magenta,5;black,7} """ @@ -56,6 +57,22 @@ def to_Conv( name, s_filer=256, n_filer=64, offset="(0,0,0)", to="(0,0,0)", widt }; """ +# FullCon +def to_FulCon( 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=\FcColor, + 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=" " ): @@ -74,7 +91,21 @@ def to_ConvConvRelu( name, s_filer=256, n_filer=(64,64), offset="(0,0,0)", to="( } }; """ - +# BatchNorm +def to_BN(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=\BatchNcolor, + opacity="""+ str(opacity) +""", + height="""+ str(height) +""", + width="""+ str(width) +""", + depth="""+ str(depth) +""" + } + }; +""" # Pool diff --git a/pycore/tikzeng.pyc b/pycore/tikzeng.pyc index ed1ff6e9..4958f903 100644 Binary files a/pycore/tikzeng.pyc and b/pycore/tikzeng.pyc differ