diff --git a/dl-transfer/Dockerfile b/dl-transfer/Dockerfile new file mode 100644 index 0000000..6929606 --- /dev/null +++ b/dl-transfer/Dockerfile @@ -0,0 +1,29 @@ +FROM nvidia/cuda:10.0-cudnn7-devel + +LABEL organization="One-Off Coder" +LABEL email="info@oneoffcoder.com" + +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/* \ No newline at end of file diff --git a/dl-transfer/README.md b/dl-transfer/README.md new file mode 100644 index 0000000..adaa81b --- /dev/null +++ b/dl-transfer/README.md @@ -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}} +``` \ No newline at end of file diff --git a/dl-transfer/build.sh b/dl-transfer/build.sh new file mode 100755 index 0000000..37bcf22 --- /dev/null +++ b/dl-transfer/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +REPOSITORY=dl-transfer +TAG=local + +docker build --no-cache -t $REPOSITORY:$TAG . \ No newline at end of file diff --git a/dl-transfer/deploy.sh b/dl-transfer/deploy.sh new file mode 100755 index 0000000..ba404d7 --- /dev/null +++ b/dl-transfer/deploy.sh @@ -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 \ No newline at end of file diff --git a/dl-transfer/image/final.jpg b/dl-transfer/image/final.jpg new file mode 100644 index 0000000..7e55011 Binary files /dev/null and b/dl-transfer/image/final.jpg differ diff --git a/dl-transfer/image/output.jpg b/dl-transfer/image/output.jpg index ab88d99..cabe1cf 100644 Binary files a/dl-transfer/image/output.jpg and b/dl-transfer/image/output.jpg differ diff --git a/dl-transfer/setup.sh b/dl-transfer/setup.sh new file mode 100755 index 0000000..a9ff27d --- /dev/null +++ b/dl-transfer/setup.sh @@ -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 \ No newline at end of file