Skip to content

Commit

Permalink
Merge pull request #7 from xmartlabs/docker
Browse files Browse the repository at this point in the history
Add Docker support
  • Loading branch information
eridgd authored Dec 14, 2017
2 parents 4884025 + 89943e1 commit 50de60a
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
Dockerfile
images
models
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
images
models/models.zip
models/relu1_1
models/relu2_1
models/relu3_1
models/relu4_1
models/relu5_1
models/vgg_normalised.t7
91 changes: 91 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
FROM tensorflow/tensorflow:1.2.1-gpu-py3

RUN sed -i "s/jessie main/jessie main contrib non-free/" /etc/apt/sources.list
RUN echo "deb http://http.debian.net/debian jessie-backports main contrib non-free" >> /etc/apt/sources.list

RUN gpg --keyserver pgpkeys.mit.edu --recv-key 7638D0442B90D010
RUN gpg -a --export 7638D0442B90D010 | apt-key add -

RUN apt-get update && \
apt-get install -y \
build-essential \
cmake \
ffmpeg \
gfortran \
git \
libatlas-base-dev \
libavcodec-dev \
libavformat-dev \
libcanberra-gtk-module \
libgtk2.0-dev \
libjasper-dev \
libjpeg-dev \
libpng-dev \
libpng12-dev \
libpq-dev \
libswscale-dev \
libtbb-dev \
libtbb2 \
libtiff-dev \
libtiff5-dev \
libv4l-dev \
libx264-dev \
libxvidcore-dev \
pkg-config \
python2.7-dev \
python3.5-dev \
python-pip \
unzip \
wget \
yasm \
&& rm -rf /var/lib/apt/lists/*

RUN pip3 install numpy
RUN pip2 install numpy

WORKDIR /
RUN wget https://github.com/opencv/opencv_contrib/archive/3.2.0.zip \
&& unzip 3.2.0.zip \
&& rm 3.2.0.zip

RUN wget https://github.com/Itseez/opencv/archive/3.2.0.zip \
&& unzip 3.2.0.zip \
&& mkdir /opencv-3.2.0/cmake_binary \
&& cd /opencv-3.2.0/cmake_binary \
&& cmake -DBUILD_TIFF=ON \
-DBUILD_opencv_java=OFF \
-DOPENCV_EXTRA_MODULES_PATH=/opencv_contrib-3.2.0/modules \
-DWITH_CUDA=OFF \
-DENABLE_AVX=ON \
-DWITH_OPENGL=ON \
-DWITH_OPENCL=ON \
-DWITH_IPP=ON \
-DWITH_TBB=ON \
-DWITH_EIGEN=ON \
-DWITH_V4L=ON \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-DPYTHON_EXECUTABLE=$(which python3) \
-DPYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-DPYTHON_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") .. \
&& make install \
&& rm /3.2.0.zip \
&& rm -r /opencv-3.2.0 \
&& rm -r /opencv_contrib-3.2.0

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD python3 webcam.py \
--checkpoints models/relu5_1 models/relu4_1 models/relu3_1 models/relu2_1 models/relu1_1 \
--relu-targets relu5_1 relu4_1 relu3_1 relu2_1 relu1_1 \
--style-size 512 \
--alpha 0.8 \
--style-path images
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ There are also four keyboard shortcuts:

`stylize.py` will stylize content images and does not require OpenCV. The options are the same as for the webcam script with the addition of `--content-path`, which can be a single image file or folder, and `--out-path` to specify the output folder. Each style in `--style-path` will be applied to each content image.

## Running with Docker

1. Download VGG19 model: `bash models/download_vgg.sh`

2. Download checkpoints for the five decoders: `bash models/download_models.sh`

3. Obtain style images and save them in a new folder `images` in the repository. Two good sources are the [Wikiart dataset](https://www.kaggle.com/c/painter-by-numbers) and [Describable Textures Dataset](https://www.robots.ox.ac.uk/~vgg/data/dtd/).

4. Install [nvidia-docker](https://github.com/NVIDIA/nvidia-docker).

5. To run the webcam example:

```shell
nvidia-docker build -t wct-tf . # It will take several minutes.
xhost +local:root
nvidia-docker run \
-ti \
--rm \
-v $PWD/models:/usr/src/app/models \
-v $PWD/images:/usr/src/app/images \
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
-e QT_X11_NO_MITSHM=1 \
-e DISPLAY \
--device=/dev/video0:/dev/video0 \
wct-tf
```

## Training

Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
keras==2.0.9
scikit-image
#tensorflow==1.2.1 # Not added to choose the TF implementaion
torchfile

0 comments on commit 50de60a

Please sign in to comment.