Skip to content

Commit

Permalink
add docker
Browse files Browse the repository at this point in the history
  • Loading branch information
vangj committed Jan 22, 2020
1 parent d00a012 commit 378c359
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 0 deletions.
29 changes: 29 additions & 0 deletions dl-transfer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM nvidia/cuda:10.0-cudnn7-devel

LABEL organization="One-Off Coder"
LABEL email="[email protected]"

ENV DEBIAN_FRONTEND=noninteractive
ENV CONDA_HOME="/opt/anaconda"
ENV PATH="${CONDA_HOME}/bin:${PATH}"

# setup environment
RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install wget -y

# setup conda
RUN wget -q https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh -O /tmp/anaconda.sh \
&& /bin/bash /tmp/anaconda.sh -b -p $CONDA_HOME \
&& conda install --yes -c pytorch pytorch torchvision cudatoolkit=10.0 \
&& python -c "from torchvision import models; models.vgg19(pretrained=True)"

# setup app
COPY . /app
VOLUME [ "/app/images" ]
WORKDIR /app
ENTRYPOINT [ "python", "app.py" ]
CMD [ "--help" ]

# clean up
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
57 changes: 57 additions & 0 deletions dl-transfer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
![One-Off Coder Logo](../logo.png "One-Off Coder")

# Purpose

This project is an executable container for Neural Style Transfer. At a high level, you supply content and style images as inputs, and the application will mix the style and content to produce a new image that is as faithful as possible to the style in the style image and the content in the content image.

Content Image

![Content Image](image/dancing.jpg "Content Image")

Style Image

![Style Image](image/picasso-01.jpg "Style Image")

Output Image

![Output Image](image/output.jpg "Output Image")

# Docker Hub

[Image](https://hub.docker.com/r/oneoffcoder/dl-transfer)

# Usage

To use the container, type in the following. Note that the `-s` flag specifies the style image and `-c` specifies the content image. By default, an `image/output.jpg` file be created. To control the output image, specify `-o` (e.g. `-o image/final.jpg`).

```bash
docker run -it \
-v `pwd`/image:/app/image \
--gpus=all \
--shm-size=5g \
oneoffcoder/dl-transfer -s image/picasso-01.jpg -c image/dancing.jpg

docker run -it \
-v `pwd`/image:/app/image \
--gpus=all \
--shm-size=5g \
dl-transfer:local -s image/picasso-01.jpg -c image/dancing.jpg

docker run -it \
-v `pwd`/image:/app/image \
--gpus=all \
--shm-size=5g \
dl-transfer:local -s image/picasso.jpg -c image/dancing.jpg -o image/final.jpg
```

# Citation

```
@misc{oneoffcoder_dl_transfer_2019,
title={An executable docker container with Neural Style Transfer},
url={https://github.com/oneoffcoder/docker-containers/tree/master/dl-transfer},
journal={GitHub},
author={One-Off Coder},
year={2020},
month={Jan}}
```
6 changes: 6 additions & 0 deletions dl-transfer/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

REPOSITORY=dl-transfer
TAG=local

docker build --no-cache -t $REPOSITORY:$TAG .
14 changes: 14 additions & 0 deletions dl-transfer/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

ORGANIZATION=oneoffcoder
REPOSITORY=dl-transfer
VERSION=0.0.1
IMAGEID=${REPOSITORY}:local

echo ${IMAGEID}

docker tag ${IMAGEID} ${ORGANIZATION}/${REPOSITORY}:${VERSION}
docker tag ${IMAGEID} ${ORGANIZATION}/${REPOSITORY}:latest

docker push ${ORGANIZATION}/${REPOSITORY}:${VERSION}
docker push ${ORGANIZATION}/${REPOSITORY}:latest
Binary file added dl-transfer/image/final.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dl-transfer/image/output.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions dl-transfer/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

updateAptPackages() {
echo "installing packages via APT"
apt-get update -y
apt-get upgrade -y
apt-get install wget -y
}

installAnaconda() {
echo "installing anaconda"
wget -q https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh -O /tmp/anaconda.sh
/bin/bash /tmp/anaconda.sh -b -p $CONDA_HOME
rm -fr /tmp/anaconda.sh
}

installPytorch() {
echo "installing pytorch"
conda install --yes \
-c pytorch pytorch torchvision cudatoolkit=10.0
}

downloadModels() {
echo "downloading models"
declare -a models=("vgg19")

for model in ${models[@]}; do
package="from torchvision import models; models.${model}(pretrained=True)"
echo $package
python -c "$package"
done
}

updateAptPackages
installAnaconda
installPytorch
downloadModels

0 comments on commit 378c359

Please sign in to comment.