画風を変換するアルゴリズムの別実装neural-styleを動かしてみる
画風を変換するアルゴリズム | Preferred Research
すごい。
でも、Chainerの使い方よく分からないので別に提案されてる実装で試してみた。
環境構築
例によって、手元の環境を汚したくないのでDockerを使って試す。
https://github.com/jcjohnson/neural-style/blob/master/INSTALL.mdこれを参考にしてDockerfileを作る。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
FROM ubuntu:14.04 RUN apt-get update RUN apt-get -y upgrade RUN apt-get install -y wget RUN apt-get -y install curl libprotobuf-dev protobuf-compiler wget lua5.2 liblua5.2-dev RUN \ cd ~/ && \ 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 RUN rm /bin/sh && ln -s /bin/bash /bin/sh RUN source ~/.bashrc RUN \ cd ~/ && \ wget http://luarocks.org/releases/luarocks-2.2.0.tar.gz && \ tar -xzvf luarocks-2.2.0.tar.gz && \ rm -f luarocks-2.2.0.tar.gz && \ cd luarocks-2.2.0/ && \ ./configure && \ make build && \ make install && \ make clean && \ cd ../ && \ rm -rf luarocks-2.2.0/ RUN \ cd ~/ && \ git clone https://github.com/jcjohnson/neural-style.git |
で、buildしてrunする。
1 2 |
docker build -t neural-art:0.0.1 . docker run -v /volume:/root/volume -it neural-art:0.0.1 /bin/bash |
loadcaffeのインストールもDockerfile内で完結させたかった。
Dockerfile内でインストールしたloadcaffeはneural-styleで参照されない。
インストールの仕方が悪いと思うのだが、ちょっとよくわからないので放置。
なので、run後にインストールした。
1 |
luarocks install loadcaffe |
neural-styleで使用するモデルをダウンロードする。
ファイルサイズが大きいのでVOLUMEでホスト側のストレージに落とすようにしておくのがいいかも。
1 2 |
cd ~/neural-style sh models/download_models.sh |
これで環境は整う。
GPUで計算したい場合は別途依存ライブラリを導入する必要がある。
動かしてみる
例えば、ブラット・ピットの写真をムンク風にしてみる。
1 |
th neural_style.lua -gpu -1 -model_file ../PATH/TO/VGG_ILSVRC_19_layers.caffemodel -image_size 256 -style_image examples/inputs/the_scream.jpg -content_image examples/inputs/brad_pitt.jpg |
image_sizeオプション(オプション指定しないと512となる)でサイズを小さくしておくとCPUでもなんとか終わる。
これが
と掛け合わさって
こうなる。
336px
336px
関連記事
-
-
MacでKerasを使えるようにする
Ke …
-
-
deepdreamしてみたい
ht …
- PREV
- メンズの秋コーディネートは難しい
- NEXT
- iOSのUI実装でよく遭遇する細々とした問題への対処法