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
48 changes: 24 additions & 24 deletions PlotNeuralNet/PyCore/Blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def Block2ConvPool(
name,
botton,
top,
sFiler=256,
nFiler=64,
sFilter=256,
nFilter=64,
offset="(1,0,0)",
size=(32, 32, 3.5),
opacity=0.5,
Expand All @@ -23,9 +23,9 @@ def Block2ConvPool(
The node from which the block starts.
top : str
The node where the block ends.
sFiler : int, optional
sFilter : int, optional
Size of the filter, by default 256.
nFiler : int, optional
nFilter : int, optional
Number of filters, by default 64.
offset : str, optional
Position offset, by default "(1,0,0)".
Expand All @@ -42,8 +42,8 @@ def Block2ConvPool(
return [
ToConvConvRelu(
name=f"ccr_{name}",
sFiler=str(sFiler),
nFiler=(nFiler, nFiler),
sFilter=str(sFilter),
nFilter=(nFilter, nFilter),
offset=offset,
to=f"({botton}-east)",
width=(size[2], size[2]),
Expand All @@ -67,8 +67,8 @@ def BlockUnconv(
name,
botton,
top,
sFiler=256,
nFiler=64,
sFilter=256,
nFilter=64,
offset="(1,0,0)",
size=(32, 32, 3.5),
opacity=0.5,
Expand All @@ -84,9 +84,9 @@ def BlockUnconv(
The node from which the block starts.
top : str
The node where the block ends.
sFiler : int, optional
sFilter : int, optional
Size of the filter, by default 256.
nFiler : int, optional
nFilter : int, optional
Number of filters, by default 64.
offset : str, optional
Position offset, by default "(1,0,0)".
Expand Down Expand Up @@ -114,8 +114,8 @@ def BlockUnconv(
name=f"ccr_res_{name}",
offset="(0,0,0)",
to=f"(unpool_{name}-east)",
sFiler=str(sFiler),
nFiler=str(nFiler),
sFilter=str(sFilter),
nFilter=str(nFilter),
width=size[2],
height=size[0],
depth=size[1],
Expand All @@ -125,8 +125,8 @@ def BlockUnconv(
name=f"ccr_{name}",
offset="(0,0,0)",
to=f"(ccr_res_{name}-east)",
sFiler=str(sFiler),
nFiler=str(nFiler),
sFilter=str(sFilter),
nFilter=str(nFilter),
width=size[2],
height=size[0],
depth=size[1],
Expand All @@ -135,8 +135,8 @@ def BlockUnconv(
name=f"ccr_res_c_{name}",
offset="(0,0,0)",
to=f"(ccr_{name}-east)",
sFiler=str(sFiler),
nFiler=str(nFiler),
sFilter=str(sFilter),
nFilter=str(nFilter),
width=size[2],
height=size[0],
depth=size[1],
Expand All @@ -146,8 +146,8 @@ def BlockUnconv(
name=f"{top}",
offset="(0,0,0)",
to=f"(ccr_res_c_{name}-east)",
sFiler=str(sFiler),
nFiler=str(nFiler),
sFilter=str(sFilter),
nFilter=str(nFilter),
width=size[2],
height=size[0],
depth=size[1],
Expand All @@ -161,8 +161,8 @@ def BlockRes(
name,
botton,
top,
sFiler=256,
nFiler=64,
sFilter=256,
nFilter=64,
offset="(0,0,0)",
size=(32, 32, 3.5),
opacity=0.5,
Expand All @@ -180,9 +180,9 @@ def BlockRes(
The node from which the block starts.
top : str
The node where the block ends.
sFiler : int, optional
sFilter : int, optional
Size of the filter, by default 256.
nFiler : int, optional
nFilter : int, optional
Number of filters, by default 64.
offset : str, optional
Position offset, by default "(0,0,0)".
Expand All @@ -204,8 +204,8 @@ def BlockRes(
name=f"{layerName}",
offset=offset,
to=f"({botton}-east)",
sFiler=str(sFiler),
nFiler=str(nFiler),
sFilter=str(sFilter),
nFilter=str(nFilter),
width=size[2],
height=size[0],
depth=size[1],
Expand Down
47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ This package is based on the original **[PlotNeuralNet by HarisIqbal88](https://
### **Installation**

1. Clone the repository:

```bash
git clone https://github.com/<your-username>/PlotNeuralNet.git
git clone https://github.com/kgruiz/PlotNeuralNet.git
cd PlotNeuralNet
```

2. Install the package:

```bash
pip install .
```

3. Verify the installation:

```python
import PlotNeuralNet
print("PlotNeuralNet installed successfully!")
Expand All @@ -50,45 +53,50 @@ The package is organized to simplify the creation of diagrams. It includes Pytho
You can use the Python API to define your architecture programmatically. For example:

```python
from PlotNeuralNet.pycore import tikzeng
from PlotNeuralNet.pycore.blocks import block_2ConvPool, block_Unconv
from PlotNeuralNet.PyCore import TikzGen as tikzeng
from PlotNeuralNet.PyCore.Blocks import Block2ConvPool, BlockUnconv

# Define architecture
arch = [
tikzeng.to_head('..'),
tikzeng.to_cor(),
tikzeng.to_begin(),

tikzeng.ToHead(".."),
tikzeng.ToCor(),
tikzeng.ToBegin(),
# Input image
tikzeng.to_input('../examples/fcn8s/cats.jpg'),

tikzeng.ToInput('./PlotNeuralNet/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),

*Block2ConvPool(name="b1", botton="input", top="b2", sFilter=256, nFilter=64),
*Block2ConvPool(name="b2", botton="b2", top="b3", sFilter=128, nFilter=128),
# Decoder
*block_Unconv(name='b4', botton='b3', top='output', s_filer=64, n_filer=32),

*BlockUnconv(name="b4", botton="b3", top="output", sFilter=64, nFilter=32),
# Output layer
tikzeng.to_ConvSoftMax(name='softmax', offset="(1,0,0)", to="(output-east)", width=1, height=30, depth=30),
tikzeng.to_end(),
tikzeng.ToConvSoftMax(
name="softmax",
offset="(1,0,0)",
to="(output-east)",
width=1,
height=30,
depth=30,
),
tikzeng.ToEnd(),
]

# Generate the architecture diagram
def main():
tikzeng.to_generate(arch, "my_architecture.tex")
tikzeng.ToGenerate(arch, "my_architecture.tex")

if __name__ == "__main__":
main()
```

#### **Compile and View the Diagram**
Run the Python script:

```bash
python my_architecture.py
```

Compile the `.tex` file with:

```bash
bash ../tikzmake.sh my_architecture
```
Expand All @@ -100,6 +108,7 @@ 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:

```bash
pdflatex <file>.tex
```
Expand All @@ -112,6 +121,7 @@ The package structure includes predefined resources for easy reuse:
#### **LaTeX Resources**
- Available in the `PlotNeuralNet/layers/` directory.
- Example LaTeX layer definitions:

```latex
\input{layers/Box.sty}
```
Expand All @@ -123,6 +133,7 @@ The package structure includes predefined resources for easy reuse:
#### **Python Scripts**
- Python examples for generating diagrams programmatically are in `PlotNeuralNet/pyexamples/`.
- Example usage:

```bash
python PlotNeuralNet/pyexamples/unet.py
```
Expand Down Expand Up @@ -172,4 +183,4 @@ This package is based on the original **[PlotNeuralNet by HarisIqbal88](https://

## **License**

This project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for more details.
This project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for more details.
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ name = "PlotNeuralNet"
version = "0.1.0"
description = "Visualize neural networks with a focus on easy-to-use diagrams."
readme = "README.md"
readme-content-type = "text/markdown"
authors = [
{name = "Kaden Gruizenga", email = "kgruiz@umich.edu"}
]
Expand All @@ -22,4 +21,4 @@ dependencies = [] # Add runtime dependencies if needed

[project.urls]
Source = "https://github.com/kgruiz/PlotNeuralNet"
Original Work = "https://github.com/HarisIqbal88/PlotNeuralNet"
"Original Work" = "https://github.com/HarisIqbal88/PlotNeuralNet"