Skip to content

Commit

Permalink
Allow 's_size' parameter to be changed via an environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
liamjones committed Feb 25, 2017
1 parent fc956fb commit 4041348
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
17 changes: 11 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ RUN apt-get update && \

ENV PAINTSCHAINER_MODEL=original \
PAINTSCHAINER_GPU=0 \
PAINTSCHAINER_S_SIZE=128 \
TINI_VERSION=0.14.0 \
DOCKERIZE_VERSION=0.3.0 \
PATH=/opt/conda/bin:$PATH \
CFLAGS=-I/usr/local/cuda-8.0/targets/x86_64-linux/include/:$CFLAGS \
LDFLAGS=-L/usr/local/cuda-8.0/targets/x86_64-linux/lib/:$LDFLAGS \
Expand All @@ -21,7 +23,10 @@ ENV PAINTSCHAINER_MODEL=original \
RUN curl --location "https://github.com/liamjones/PaintsChainer-Models/releases/download/{$PAINTSCHAINER_MODEL}/unet_128_standard" > unet_128_standard && \
curl --location "https://github.com/liamjones/PaintsChainer-Models/releases/download/{$PAINTSCHAINER_MODEL}/unet_512_standard" > unet_512_standard && \
curl --location "https://github.com/liamjones/PaintsChainer-Models/releases/download/{$PAINTSCHAINER_MODEL}/License.txt" > Licence.txt && \
curl --location "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini" > /tini
curl --location "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini" > /usr/local/bin/tini && \
curl --location "https://github.com/jwilder/dockerize/releases/download/v$DOCKERIZE_VERSION/dockerize-linux-amd64-v$DOCKERIZE_VERSION.tar.gz" > /dockerize.tar.gz && \
tar -C /usr/local/bin -zxvf /dockerize.tar.gz && \
rm /dockerize.tar.gz

# Re-running apt-get update because we're hoping to cache the Anaconda layer for a while
RUN mkdir --parents /opt/conda/var/lib/dbus/ & \
Expand All @@ -34,10 +39,9 @@ RUN mkdir --parents /opt/conda/var/lib/dbus/ & \
tmpreaper && \
apt-get clean && \
rm --recursive --force /var/lib/apt/lists/* && \
chmod +x /tini && \
chmod +x /usr/local/bin/tini && \
conda install --yes --channel menpo opencv3 && \
conda clean --all && \
pip --no-cache-dir install --upgrade pip && \
pip --no-cache-dir install chainer

ENV PAINTSCHAINER_REPO=https://github.com/pfnet/PaintsChainer.git \
Expand All @@ -59,10 +63,11 @@ COPY *.patch ./

RUN git checkout $PAINTSCHAINER_COMMIT && \
git apply *.patch && \
rm *.patch
rm *.patch && \
mv server.py server.py.template

EXPOSE 8000

ENTRYPOINT [ "/tini", "-g", "--" ]
ENTRYPOINT [ "tini", "-g", "--" ]

CMD [ "sh", "-c", "cron && python -u server.py --host 0.0.0.0 --gpu $PAINTSCHAINER_GPU"]
CMD [ "sh", "-c", "cron && dockerize --template server.py.template:server.py && python -u server.py --host 0.0.0.0 --gpu $PAINTSCHAINER_GPU"]
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ If you want to run this on Windows and have no familiarity with Docker, etc you
Ensure you have [nvidia-docker](https://github.com/NVIDIA/nvidia-docker) installed for GPU passthrough to containers. To run with the default GPU:

```console
$ nvidia-docker run --rm -p 8000:8000 liamjones/paintschainer-docker
$ nvidia-docker run --name paintschainer --rm -p 8000:8000 liamjones/paintschainer-docker
```

If you have multiple GPUs and want to specify an alternate one you can specify GPU number via an environment variable:

```console
$ nvidia-docker run --rm -p 8000:8000 -e PAINTSCHAINER_GPU=1 liamjones/paintschainer-docker
$ nvidia-docker run --name paintschainer --rm -p 8000:8000 -e PAINTSCHAINER_GPU=1 liamjones/paintschainer-docker
```

GPU numbers can be verified by running:

```console
$ docker run liamjones/paintschainer-docker nvidia-smi
$ docker run --rm liamjones/paintschainer-docker nvidia-smi
```

## Processing via CPU
Expand All @@ -35,7 +35,7 @@ This will be slower than GPU processing but has some advantages;
* Can potentially process larger images (assuming you have more RAM than VRAM)

```console
$ docker run --rm -p 8000:8000 -e PAINTSCHAINER_GPU=-1 liamjones/paintschainer-docker
$ docker run --name paintschainer --rm -p 8000:8000 -e PAINTSCHAINER_GPU=-1 liamjones/paintschainer-docker
```

## Access the web interface
Expand Down
13 changes: 13 additions & 0 deletions apply-dockerize-template.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/server.py b/server.py
index 3ddc1a9..f1c914d 100755
--- a/server.py
+++ b/server.py
@@ -114,7 +114,7 @@ class MyHandler(http.server.CGIHTTPRequestHandler):
blur = 0

self.log_t()
- painter.colorize(id_str, form["step"][0].decode() if "step" in form else "C", blur=blur)
+ painter.colorize(id_str, form["step"][0].decode() if "step" in form else "C", blur=blur, s_size={{ .Env.PAINTSCHAINER_S_SIZE }})

self.log_t()
self.ret_result(True)

0 comments on commit 4041348

Please sign in to comment.