意馬心猿 - いばしんえん

欲望のままにプログラミング

人工知能による画像合成”ostagram”の実行環境を整える【Mac】

 

1. Torch7のインストール

git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; bash install-deps
./install.sh

この際、以前にhomebrew等でimagemagickwgetなどのパッケージをインストールしている場合、
Error: imagemagick-6.9.3-0_2 already installed
To install this version, first `brew unlink imagemagick`

のようなエラーになるかもしれませんが、その場合はエラーメッセージにしたがって

を実行してください。

また、上の作業が完了したら一度、

th

を実行し

______ __ | Torch7
/_ __/__ ________/ / | Scientific computing for Lua.
/ / / _ \/ __/ __/ _ \ | Type ? for help
/_/ \___/_/ \__/_//_/ | https://github.com/torch
| http://torch.ch
th> exit Do you really want to exit ([y]/n)? y

と表示されるかどうか確認してください。

※Torch7が正しくインストールされていない場合、2.のloadcaffeがインストールできません。

2. loadcaffeのインストール

brew install protobuf
luarocks install loadcaffe

この際
Error: No such keg: /usr/local/Cellar/gnuplotのようなエラーになるかもしれないですが、その場合は

brew install gnuplot

で僕は解決しました。

3. CUDAのインストール

※GeoForce等のGPU搭載PCの人以外は飛ばしてください。

以下からインストーラーをDLして実行。https://developer.nvidia.com/cuda-downloads

4. neural styleのインストール

git clone https://github.com/jcjohnson/neural-style
cd neural-style
sh models/download_models.sh

以上で環境構築の作業はおしまいです。

5. neural-styleの実行

いよいよ最後は実行です。実行は先ほど移動したneural-styleフォルダで行ってください。

 

f:id:santamalia:20160322011548j:plain

f:id:santamalia:20160322011554j:plain

f:id:santamalia:20160322013914p:plain

左がstyle-image01.jpg、右がcontent-image01.jpgです。

th neural_style.lua -style_image /style01.jpg -content_image /content01.jpg -gpu -1
を実行で、下のように合成されました。※CUDAをインストールした人は末尾の"-gpu -1"は入力する必要はありません。

今はGoogle人工知能囲碁で人間に勝利したり、人工知能が激アツです!みなさんもぜひおためしあれ!

【参考URL】

人工知能で画像合成させる「ostagram」実行環境の作り方 - Hacking My Way 〜 itogのhack日記

Torch | Getting started with Torch

https://www.facebook.com/ostagram/

https://research.preferred.jp/2015/09/chainer-gogh/