tensorflowでstyleTransfer

anacondaから環境作成して以下各種インストール

conda install 
・tensorflow-gpu
・pillow
・scipy
・numpy
・moviepy

ffmpegをダウンロードして環境変数パスを通す。

ffmpeg
https://www.ffmpeg.org/download.html
パスの通し方
https://note.mu/uneori/n/n500f7e814fd8

クローンしてくる

git clone https://github.com/lengstrom/fast-style-transfer.git

setup.shを実行する。または手動でセットアップ

dataフォルダ作成し学習済みモデルデータを落として配置
http://www.vlfeat.org/matconvnet/models/beta16/imagenet-vgg-verydeep-19.mat
dataフォルダ内にimagenetのデータを落として解凍し配置※
http://msvocds.blob.core.windows.net/coco2014/train2014.zip

imagenetのデータがめちゃデカい。checkpointを生成しない場合、つまりすでに作成されたcheckpointを使った変換でよければここはいらない。
作成されたcheckpointはリポジトリリンクの「Evaluating Style Transfer Networks」部分 located here のとこににあるので落としてcheckpointフォルダに突っ込む。ミュシャとかいろいろある。
https://github.com/lengstrom/fast-style-transfer

Checkpointを生成

styleの引数に作りたいcheckpoint用のstyle画像を指定
うまくいくとcheckpointフォルダ内に4つのckptファイルが生成される。

python style.py --style examples/style/style.jpg --checkpoint-dir checkpoint

--checkpoint-dir: 
--style: 
--train-path: 
--test: 
--test-dir: 
--epochs: 
--batch_size: 
--checkpoint-iterations: 
--vgg-path: 
--content-weight: 
--style-weight: 
--tv-weight: 
--learning-rate: 

checkpointを用いて画風変換

引数でcheckpointと入力画像、出力ディレクトリを指定。
先ほどの方法で生成したcheckpointを使う場合は4つのファイルがある場所でfns.ckptで指定できるみたい。

python evaluate.py --checkpoint checkpoint/la_muse.ckpt --in-path in/in.jpg --out-path out/out.jpg

できる。。


この記事が気に入ったらサポートをしてみませんか?