Running tensorflow version of neural style in Docker

## Overview

The relevant codes are all on Github, please refer to my Github, https://github.com/lijingpeng/neural-style
, please pay more attention~~~

## Docker image build

The Dockerfile is as follows:

FROM tensorflow/tensorflow:latest

RUN echo deb http://mirrors.aliyun.com/ubuntu trusty universe >> /etc/apt/sources.list
RUN echo deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse >> /etc/apt/sources.list
RUN echo deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse >> /etc/apt/sources.list
RUN echo deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse >> /etc/apt/sources.list
RUN echo deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse >> /etc/apt/sources.list
RUN echo deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse >> /etc/apt/sources.list
RUN echo deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse >> /etc/apt/sources.list
RUN echo deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse >> /etc/apt/sources.list
RUN echo deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse >> /etc/apt/sources.list
RUN echo deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse >> /etc/apt/sources.list
RUN echo deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse >> /etc/apt/sources.list
RUN apt-get update

# clone code
RUN apt-get install -y --no-install-recommends git
RUN git clone https://github.com/anishathalye/neural-style.git

# install pillow and its dependences
RUN apt-get install -y libffi-dev libssl-dev libtiff5-dev libjpeg8-dev zlib1g-dev \
    libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk
RUN pip install --trusted-host pypi.douban.com -i http://pypi.douban.com/simple/ -U pip
RUN pip install --trusted-host pypi.douban.com -i http://pypi.douban.com/simple/ -U Pillow
# RUN pip install --trusted-host pypi.douban.com -i http://pypi.douban.com/simple/ -U pyopenssl ndg-httpsclient pyasn1

# Too slow, use docker volume instead
# RUN apt-get install -y wget
# RUN wget http://www.vlfeat.org/matconvnet/models/beta16/imagenet-vgg-verydeep-19.mat
# RUN mv imagenet-vgg-verydeep-19.mat neural-style

CMD ["/run_jupyter.sh"]

Copy this code, create a file called Dockerfile, and execute:

docker build -t docker_neural_style .

Notice:

  1. The construction of this image is based on the official Tensorflow, please use it with confidence
  2. Rely on the trained network: imagenet-vgg-verydeep-19.mat, this file has more than 500M, the download site is abroad, it is not recommended to download directly during the Docker build process, you can use a download tool such as Thunder to download to the local, and then put The file can be mapped to the container.

## Download the trained deep network

wget http://www.vlfeat.org/matconvnet/models/beta16/imagenet-vgg-verydeep-19.mat

Suppose the file is saved in the /Users/you/ directory

## Execute in Docker

docker run -it -p 8888:8888 -v /Users/you:/notebooks/neural-style-mat docker_neural_style /bin/bash

Note: This command maps /Users/you/ to /notebooks/neural-style-mat in the container and starts the container.

python neural_style.py --content examples/1-content.jpg --styles examples/1-style.jpg --output examples/myoutput.jpg --network ../neural-style-mat/imagenet-vgg-verydeep-19.mat

Execute the neural_style script.
It should be noted that Tensorflow does not support L-BFGS, and the implementation by Tensorflow is about three times slower than Torch. On the author's MacBook Pro, it takes about 6 hours to run Van Gogh-style paintings for 1,000 iterations on a pure CPU. In view of this, conditionally go directly to the GPU.

 

http://www.cnblogs.com/lijingpeng/p/6009476.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326932540&siteId=291194637