相关的代码都在 Github 上,请参见我的 Github,
敬请多多关注哈~~~
Dockerfile 如下:
- 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"]
复制这段代码,创建名为 Dockerfile 的文件,然后执行:
- docker build - t docker_neural_style.
注意:
- wget http: //www.vlfeat.org/matconvnet/models/beta16/imagenet-vgg-verydeep-19.mat
假设该文件保存在 /Users/you/ 目录下
- docker run - it - p 8888 : 8888 - v / Users / you: /notebooks/neural - style - mat docker_neural_style / bin / bash
注意:这条命令将 / Users/you / 映射到容器中的 / notebooks/neural-style-mat 并启动容器。
- 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
执行 neural_style 脚本。
需要注意的是 Tensorflow 不支持 L-BFGS, 并且由 Tensorflow 的实现比 Torch 慢三倍左右。在笔者的 MacBook Pro 上,纯 CPU 跑梵高风格画作迭代 1000 轮要耗时 6 个小时左右。鉴于此,有条件的直接上 GPU 吧。
来源: http://www.cnblogs.com/lijingpeng/p/6009476.html