A Neural Algorithm of Artistic Style这篇论文说明了如何使用神经网络学习一副画的绘画风格,并把这种风格带入自选照片。
比如下面这个例子,我们选择文森特·梵高的The Starry Night作为模板。学习过程让梵高灵魂附体我们的电脑,借脑还魂给我们作画。
是不是很想试试呢?下面简单说说我在Linux上的运行经验。
安装Torch
在terminal中运行以下命令
curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-deps | bash
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; ./install.sh
第一个命令安装了LuaJIT和Torch需要的依赖。 第二个命令安装了LuaJIT, LuaRocks,然后用LuaRocks安装了torch, nn,paths等.
脚本也添加了torch PATH到环境中,所以需要重启终端或者运行
source ~/.bashrc
有可能需要更新image包到最新
luarocks install image
安装loadcaffe
caffe的依赖比较简单,只需要安装protobuf
sudo apt-get install libprotobuf-dev protobuf-compiler
然后安装loadcaffe
luarocks install loadcaffe
下载Neural Style的实现
先移动到你想存放项目的目录下。
Git clone https://github.com/jcjohnson/neural-style.git
sh models/download_models.sh
Git拷贝实现代码。
第二行下载训练好的神经网络模型VGG-19和它的改进型,VGG-19为默认设置。
默认设置运行使用
th neural_style.lua -style_image <image.jpg> -content_image <image.jpg>
如果是公司电脑没有显卡,加上 -gpu -1
Run run run
下面是大师为我画的一些作品~~