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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@ venv.bak/
/site

# mypy
.mypy_cache/
.mypy_cache/

# Docker log
docker_build.log
121 changes: 121 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# The Linux distro install instructions from https://miktex.org/download are used here.
# This Dockerfile creates a docker container that has all necessary packages installed to create the NN diagrams
# Remember, if needed to rebuild, look at the README for cmd line instructions
#
# Authors: [Christopher Endres ([email protected])]
# Date Created: 06/26/2023
# Last Updated: 06/26/2023
# Version: 1.0

### Stage 1, use Ubuntu 20.04 as base image ###
FROM ubuntu:20.04 AS base

# Set home directory
ENV HOME=/home/pnn
WORKDIR $HOME

# Set user to root
USER root

# Set env name
ARG ENV_NAME=pnn

# Update and install dependencies for python3.10 install
RUN apt-get update -y && \
apt-get install software-properties-common -y && \
add-apt-repository ppa:deadsnakes/ppa

# Install python3.10 and other dependencies
RUN apt-get install python3.10 -y && \
apt-get install -y python3-distutils python3-pip python3-apt

# Remove python3 virtualenv, install virtualenv
RUN apt-get remove -y python3-virtualenv && \
pip install --user virtualenv --force-reinstall

# Add the 'tree' command for debugging
RUN apt-get update && \
apt-get install -y tree


### Stage 2, install miktex ###
# All credits to this stage go to Christian Schenk, contents can be found at https://github.com/MiKTeX/docker-miktex/blob/master/Dockerfile
FROM base AS miktex

# Install dependencies for miktex
RUN apt-get update && \
apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \
dirmngr \
ghostscript \
gnupg \
gosu \
make \
perl

# Download mixtex from source
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys D6BC243565B2087BC3F897C9277A7293F59E4889
RUN echo "deb http://miktex.org/download/ubuntu focal universe" | tee /etc/apt/sources.list.d/miktex.list

# Install miktex
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
miktex

# Setup miktex
RUN miktexsetup finish && \
initexmf --admin --set-config-value=[MPM]AutoInstall=1 && \
mpm --admin \
--install amsfonts \
--install biber-linux-x86_64 && \
initexmf --admin --update-fndb

### Stage 3, setup python venv and install poetry dependencies ###
FROM miktex AS env_setup

# Set Python/pip/Poetry ENV settings
ENV YOUR_ENV=${ENV_NAME} \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
PSUTILS_VERSION=5.9.4 \
POETRY_VERSION=1.4.1 \
PIP_VERSION=22.3.1

# Install Poetry ans psutil, upgrade requests
RUN pip install --upgrade --user requests && \
pip install --user "psutil==$PSUTILS_VERSION" && \
pip install --user "poetry==$POETRY_VERSION" && \
pip install --user "pip==$PIP_VERSION"

# Set project app workspace in linux distro
ENV WORK_DIR=$HOME/app

# Copy the poetry lock and pyproject toml file to the Dockerfile working dir (assuming the lock and toml files are in same dir as Dockerfile)
WORKDIR $WORK_DIR
# COPY poetry.lock $WORK_DIR/poetry.lock
# COPY pyproject.toml $WORK_DIR/pyproject.toml

# Copy the project files to the Dockerfile working dir (assuming the project files are in same dir as Dockerfile)
COPY . $WORK_DIR

# Set Poetry and Venv paths
ENV POETRY_PATH=$HOME/.poetry/bin/poetry \
VENV_PATH=$HOME/.local/bin/venv \
BIN_PATH=$HOME/.local/bin/

# Add poetry, venv, and bin to path
ENV PATH="$POETRY_PATH:$VENV_PATH:$BIN_PATH:$PATH"

# Create virtual env
RUN poetry config virtualenvs.create true && \
poetry config virtualenvs.options.system-site-packages true

# Install Poetry dependencies from lock file via requirements.txt file rather than poetry install (sometimes poetry install breaks from depreciated pip install)
RUN poetry export --without-hashes --with dev --format=requirements.txt > requirements.txt && \
pip install --user -r requirements.txt && \
rm requirements.txt
65 changes: 45 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# PlotNeuralNet

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2526396.svg)](https://doi.org/10.5281/zenodo.2526396)

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.
Expand All @@ -10,39 +11,62 @@ Following are some network representations:
<p align="center"><img src="https://user-images.githubusercontent.com/17570785/50308846-c2231880-049c-11e9-8763-3daa1024de78.png" width="85%" height="85%"></p>
<h6 align="center">FCN-8 (<a href="https://www.overleaf.com/read/kkqntfxnvbsk">view on Overleaf</a>)</h6>


<p align="center"><img src="https://user-images.githubusercontent.com/17570785/50308873-e2eb6e00-049c-11e9-9587-9da6bdec011b.png" width="85%" height="85%"></p>
<h6 align="center">FCN-32 (<a href="https://www.overleaf.com/read/wsxpmkqvjnbs">view on Overleaf</a>)</h6>


<p align="center"><img src="https://user-images.githubusercontent.com/17570785/50308911-03b3c380-049d-11e9-92d9-ce15669017ad.png" width="85%" height="85%"></p>
<h6 align="center">Holistically-Nested Edge Detection (<a href="https://www.overleaf.com/read/jxhnkcnwhfxp">view on Overleaf</a>)</h6>

## Getting Started

1. Install the following packages on Ubuntu.
* Ubuntu 16.04
```
sudo apt-get install texlive-latex-extra
```

* Ubuntu 18.04.2
* Ubuntu 16.04

```sh
sudo apt-get install texlive-latex-extra

```

* Ubuntu 18.04.2
Base on this [website](https://gist.github.com/rain1024/98dd5e2c6c8c28f9ea9d), please install the following packages.
```
sudo apt-get install texlive-latex-base
sudo apt-get install texlive-fonts-recommended
sudo apt-get install texlive-fonts-extra
sudo apt-get install texlive-latex-extra
```

* Windows
1. Download and install [MikTeX](https://miktex.org/download).
2. Download and install bash runner on Windows, recommends [Git bash](https://git-scm.com/download/win) or Cygwin(https://www.cygwin.com/)
```sh
sudo apt-get install texlive-latex-base
sudo apt-get install texlive-fonts-recommended
sudo apt-get install texlive-fonts-extra
sudo apt-get install texlive-latex-extra

```

* Windows

1. Download and install [MikTeX](https://miktex.org/download).
2. Download and install bash runner on Windows, recommends [Git bash](https://git-scm.com/download/win) or Cygwin(https://www.cygwin.com/)

2. Execute the example as followed.
```
cd pyexamples/
bash ../tikzmake.sh test_simple
```

```sh
cd pyexamples/
bash ../tikzmake.sh test_simple
```

* Docker

1. Install [Docker](https://www.docker.com/). If using Windows, you can install Docker Desktop for Windows, or use WSL to install Docker CE for Ubuntu.
- The MikTex docker image is used as the base stage for the docker build, which is based on Ubuntu 20.04 LTS

2. Run the `docker_build.sh` file using the following command to build the docker image (from the root directory of this repo). You need bash to run this script. If using Windows, you can install Git bash or Cygwin; WSL and Linux have bash built-in.

```sh
bash build_pnn_docker.sh
```

3. Run the container in docker (from a WSL or Linux terminal) with the following command (from the root directory of this repo). Ensure the command is being run as admin of the machine.

```sh
bash start_pnn_docker.sh
```

## TODO

Expand Down Expand Up @@ -91,6 +115,7 @@ def main():

if __name__ == '__main__':
main()

```

Now, run the program as follows:
Expand Down
32 changes: 32 additions & 0 deletions build_pnn_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# Script to build the docker container
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR

# Try to stop docker if it is running.
echo "Stopping docker..."
sudo killall -9 dockerd || :

# If the docker.pid file exists, then delete it
rm -rf /var/run/docker.pid || :

# Start docker in the background.
echo "Starting docker..."
sudo dockerd &
sleep 5

# Enable buildkit
export DOCKER_BUILDKIT=1

# Remove all builds not built in the last 24 hours and not associated with a container
yes y 2>/dev/null | docker image prune -a --filter "until=24h"

# This will build the full docker image. Use buildkit inline cache.
docker build -t pnn-docker:latest \
-f Dockerfile \
--progress=plain \
--cache-from pnn-docker:latest \
--build-arg BUILDKIT_INLINE_CACHE=1 \
. 2>&1 | tee ./docker_build.log

# --no-cache \
7 changes: 7 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.poetry]
name = "plotneuralnet"
license = "MIT License"
version = "0.1.0"
description = "PlotNeuralNet creates model architectures in easy-to-digest diagrams created via LaTeX engine"
authors = ["Your Name <[email protected]>"]
readme = "README.md"
packages = [{include = "plotneuralnet"}]

[tool.poetry.dependencies]
python = ">=3.8,<3.11"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
36 changes: 36 additions & 0 deletions start_pnn_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
# Shell script to run in a WSL/Linux terminal to start the container.

# Set the name of the container.
CONTAINER_NAME=pnn

# Set the name of the image, from docker_build.sh.
IMAGE_NAME=pnn-docker
IMAGE_TAG=latest

# Get the directory of this script
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

# Set the directory for the codebase.
CODEBASE=$SCRIPT_DIR/

# Try to stop docker if it is running.
echo "Stopping docker..."
sudo killall -9 dockerd || :

# If the docker.pid file exists, then delete it
rm -rf /var/run/docker.pid || :

# Start docker in the background.
echo "Starting docker..."
sudo dockerd &
sleep 5

# Run the docker image.
echo "Running docker image..."
sudo docker run --gpus all --rm -it \
-v $CODEBASE:/app \
--name $CONTAINER_NAME \
--network host \
$IMAGE_NAME:$IMAGE_TAG