diff --git a/README.md b/README.md index 9481c92..e5cd147 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # PlotNeuralNet -[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2526396.svg)](https://doi.org/10.5281/zenodo.2526396) +[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2526396.svg)](https://doi.org/10.5281/zenodo.2526396) [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/HarisIqbal88/PlotNeuralNet/master) 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. ## TODO -- [X] Python interfaz +- [X] Python interface - [ ] Add easy legend functionality - [ ] Add more layer shapes like TruncatedPyramid, 2DSheet etc - [ ] Add examples for RNN and likes. diff --git a/binder/apt.txt b/binder/apt.txt new file mode 100644 index 0000000..0d0331b --- /dev/null +++ b/binder/apt.txt @@ -0,0 +1 @@ +texlive-full diff --git a/pycore/__init__.pyc b/pycore/__init__.pyc deleted file mode 100644 index e9f05b6..0000000 Binary files a/pycore/__init__.pyc and /dev/null differ diff --git a/pycore/tikzeng.pyc b/pycore/tikzeng.pyc deleted file mode 100644 index ed1ff6e..0000000 Binary files a/pycore/tikzeng.pyc and /dev/null differ diff --git a/pyexamples/UNetNotebook.ipynb b/pyexamples/UNetNotebook.ipynb new file mode 100644 index 0000000..25c04bd --- /dev/null +++ b/pyexamples/UNetNotebook.ipynb @@ -0,0 +1,118 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import sys, os\n", + "PLOTNN_DIR = os.path.join('..')\n", + "sys.path.append(PLOTNN_DIR)\n", + "from pycore.tikzeng import *\n", + "from pycore.blocks import *\n", + "from IPython.display import display_pdf, FileLink" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "arch = [ \n", + " to_head(PLOTNN_DIR), \n", + " to_cor(),\n", + " to_begin(),\n", + " \n", + " #input\n", + " to_input( os.path.join(PLOTNN_DIR, 'examples/fcn8s/cats.jpg') ),\n", + "\n", + " #block-001\n", + " 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 ),\n", + " to_Pool(name=\"pool_b1\", offset=\"(0,0,0)\", to=\"(ccr_b1-east)\", width=1, height=32, depth=32, opacity=0.5),\n", + " \n", + " *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 ),\n", + " *block_2ConvPool( name='b3', botton='pool_b2', top='pool_b3', s_filer=128, n_filer=256, offset=\"(1,0,0)\", size=(25,25,4.5), opacity=0.5 ),\n", + " *block_2ConvPool( name='b4', botton='pool_b3', top='pool_b4', s_filer=64, n_filer=512, offset=\"(1,0,0)\", size=(16,16,5.5), opacity=0.5 ),\n", + "\n", + " #Bottleneck\n", + " #block-005\n", + " to_ConvConvRelu( name='ccr_b5', s_filer=32, n_filer=(1024,1024), offset=\"(2,0,0)\", to=\"(pool_b4-east)\", width=(8,8), height=8, depth=8, caption=\"Bottleneck\" ),\n", + " to_connection( \"pool_b4\", \"ccr_b5\"),\n", + "\n", + " #Decoder\n", + " *block_Unconv( name=\"b6\", botton=\"ccr_b5\", top='end_b6', s_filer=64, n_filer=512, offset=\"(2.1,0,0)\", size=(16,16,5.0), opacity=0.5 ),\n", + " to_skip( of='ccr_b4', to='ccr_res_b6', pos=1.25),\n", + " *block_Unconv( name=\"b7\", botton=\"end_b6\", top='end_b7', s_filer=128, n_filer=256, offset=\"(2.1,0,0)\", size=(25,25,4.5), opacity=0.5 ),\n", + " to_skip( of='ccr_b3', to='ccr_res_b7', pos=1.25), \n", + " *block_Unconv( name=\"b8\", botton=\"end_b7\", top='end_b8', s_filer=256, n_filer=128, offset=\"(2.1,0,0)\", size=(32,32,3.5), opacity=0.5 ),\n", + " to_skip( of='ccr_b2', to='ccr_res_b8', pos=1.25), \n", + " \n", + " *block_Unconv( name=\"b9\", botton=\"end_b8\", top='end_b9', s_filer=512, n_filer=64, offset=\"(2.1,0,0)\", size=(40,40,2.5), opacity=0.5 ),\n", + " to_skip( of='ccr_b1', to='ccr_res_b9', pos=1.25),\n", + " \n", + " to_ConvSoftMax( name=\"soft1\", s_filer=512, offset=\"(0.75,0,0)\", to=\"(end_b9-east)\", width=1, height=40, depth=40, caption=\"SOFT\" ),\n", + " to_connection( \"end_b9\", \"soft1\"),\n", + " \n", + " to_end() \n", + " ]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "to_generate(arch, os.path.join(PLOTNN_DIR, 'u_out.tex'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "!pdflatex {os.path.join(PLOTNN_DIR, 'u_out.tex')}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "FileLink('u_out.pdf')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.7" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}