PlotNeuralNet is a Python package that provides tools to generate high-quality neural network architecture diagrams for research papers, presentations, and reports. It leverages LaTeX and Python for seamless integration into scientific workflows.
This package is based on the original PlotNeuralNet by HarisIqbal88, with improvements for better usability and a modular package structure.
- Programmatically generate neural network diagrams using Python.
- Predefined layer types (e.g., Conv, Pool, SoftMax).
- Easily extendable for custom layer shapes.
- Pre-built LaTeX templates for popular architectures like AlexNet, FCN, and HED.
- Fully structured as a Python package for streamlined integration into projects.
-
Clone the repository:
git clone https://github.com/<your-username>/PlotNeuralNet.git cd PlotNeuralNet
-
Install the package:
pip install .
-
Verify the installation:
import PlotNeuralNet print("PlotNeuralNet installed successfully!")
The package is organized to simplify the creation of diagrams. It includes Python modules (pycore
and pyexamples
) and LaTeX resources (layers
).
You can use the Python API to define your architecture programmatically. For example:
from PlotNeuralNet.pycore import tikzeng
from PlotNeuralNet.pycore.blocks import block_2ConvPool, block_Unconv
# Define architecture
arch = [
tikzeng.to_head('..'),
tikzeng.to_cor(),
tikzeng.to_begin(),
# Input image
tikzeng.to_input('../examples/fcn8s/cats.jpg'),
# Encoder
*block_2ConvPool(name='b1', botton='input', top='b2', s_filer=256, n_filer=64),
*block_2ConvPool(name='b2', botton='b2', top='b3', s_filer=128, n_filer=128),
# Decoder
*block_Unconv(name='b4', botton='b3', top='output', s_filer=64, n_filer=32),
# Output layer
tikzeng.to_ConvSoftMax(name='softmax', offset="(1,0,0)", to="(output-east)", width=1, height=30, depth=30),
tikzeng.to_end(),
]
# Generate the architecture diagram
def main():
tikzeng.to_generate(arch, "my_architecture.tex")
if __name__ == "__main__":
main()
Run the Python script:
python my_architecture.py
Compile the .tex
file with:
bash ../tikzmake.sh my_architecture
You can directly modify .tex
files in the examples
directory, such as examples/FCN-8
or examples/HED
. Each .tex
file demonstrates how to use LaTeX for defining architectures.
To compile a .tex
file, use:
pdflatex <file>.tex
The package structure includes predefined resources for easy reuse:
- Available in the
PlotNeuralNet/layers/
directory. - Example LaTeX layer definitions:
\input{layers/Box.sty}
- Predefined architectures like FCN, HED, AlexNet are in
PlotNeuralNet/examples/
. - Modify these examples to fit your use case.
- Python examples for generating diagrams programmatically are in
PlotNeuralNet/pyexamples/
. - Example usage:
python PlotNeuralNet/pyexamples/unet.py
The package is organized as follows:
PlotNeuralNet/
├── LICENSE # License file
├── MANIFEST.in # File inclusion rules
├── README.md # Documentation
├── setup.py # Installation script
├── PlotNeuralNet/ # Main package directory
│ ├── __init__.py # Package initializer
│ ├── pycore/ # Core Python modules
│ ├── layers/ # LaTeX resources
│ ├── examples/ # Predefined architectures in LaTeX
│ ├── pyexamples/ # Python examples
├── dist/ # Build artifacts (after running setup.py)
├── build/ # Temporary build files
-
Custom Layers
- Extend
pycore.blocks
or create your own block definitions to support custom layers.
- Extend
-
Batch Processing
- Use Python scripts to generate multiple architectures programmatically.
-
Predefined Functions
block_2ConvPool
andblock_Unconv
simplify common layer patterns.
This package is based on the original PlotNeuralNet by HarisIqbal88 and licensed under the MIT License.
This project is licensed under the MIT License. See the LICENSE file for more details.