Deep Learning
(→UbuntuAI) |
|||
| 1行: | 1行: | ||
| − | == | + | == Chainer fast Neuralstyle == |
| − | + | ||
| − | + | ;論文 | |
| + | : Justin Johnson, Alexandre Alahi, Li Fei-Fei, "Perceptual Losses for Real-Time Style Transfer and Super-Resolution" | ||
| + | : https://arxiv.org/abs/1603.08155 | ||
| − | * | + | ;実装 |
| − | * | + | *https://github.com/yusuketomoto/chainer-fast-neuralstyle |
| + | *https://github.com/gafr/chainer-fast-neuralstyle-models | ||
| + | *https://github.com/gafr/chainer-fast-neuralstyle-video | ||
| − | * | + | *http://cocodataset.org/#home |
| − | ** | + | **http://msvocds.blob.core.windows.net/coco2014/train2014.zip |
| − | + | ||
| − | * | + | スタイル学習(モデルの生成) |
| − | + | * -sでスタイル画像 | |
| − | + | * -dでダウンロードしてきた画像集のフォルダを指定 | |
| + | * -rでリジューム | ||
<pre> | <pre> | ||
| − | + | python train.py -s スタイル画像 -d 画像集フォルダ -r | |
| + | python train.py -s スタイル画像 -d train2014 -o 生成画像名 -r | ||
</pre> | </pre> | ||
| − | + | クローン | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
<pre> | <pre> | ||
| − | + | git clone https://github.com/yusuketomoto/chainer-fast-neuralstyle.git | |
| − | + | ||
| − | + | ||
</pre> | </pre> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | VGGのダウンロード。 | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
<pre> | <pre> | ||
| − | + | wget http://www.robots.ox.ac.uk/~vgg/software/very_deep/caffe/VGG_ILSVRC_16_layers.caffemodel | |
| − | + | ||
</pre> | </pre> | ||
| − | + | chainer用に変換。 | |
<pre> | <pre> | ||
| − | + | python create_chainer_model.py | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
</pre> | </pre> | ||
| 186行: | 127行: | ||
これは、指定したGPUがないか使えないということ。ドライバーをインストールしなおしたら、解決した。 | これは、指定したGPUがないか使えないということ。ドライバーをインストールしなおしたら、解決した。 | ||
| − | |||
| − | + | 画風変換 | |
| − | + | <pre> | |
| − | + | python generate.py sample_images/コンテンツ元画像.jpg -m models/学習モデル.model -o sample_images/出力画像.jpg | |
| + | </pre> | ||
| − | + | *MacBook Pro CPU 3.3GHz Intel Core i7, 16GB, intel iris Graphics 550 1536MB : 15sec | |
| − | * | + | |
| − | + | ||
| − | + | ||
| − | + | === CubistMirror === | |
| − | + | https://github.com/genekogan/CubistMirror | |
| − | + | *oF0.10では,Pocoライブラリーが機能しない。 | |
| − | * | + | **v0.10では,PocoはAddonになった。v0.9以前は,本体に入っていた模様。 |
| − | * | + | * QuickTime/QuickTime.h not found,には以下のものを使用。 |
| − | * | + | ** https://openframeworks.cc/versions/v0.9.4_RC1/ |
| + | |||
| + | == neuralart TensorFlow == | ||
| + | |||
| + | https://github.com/ckmarkoh/neuralart_tensorflow | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | == 環境設定 == | ||
| + | MacOSのLinuxで。 | ||
| + | |||
| + | === 開発環境整備 === | ||
| + | |||
| + | * homebrew | ||
| + | * pnenv | ||
| + | |||
| + | * Phthon | ||
| + | ** anaconda2 | ||
| + | ** anaconda3 | ||
| + | |||
| + | * pip | ||
| + | |||
| + | Python3 とpip3のインストール | ||
<pre> | <pre> | ||
| − | + | sudo apt install python3 python3-pip | |
| − | + | ||
</pre> | </pre> | ||
| − | + | ||
| + | == Ubuntu == | ||
| + | |||
| + | === VNC === | ||
| + | Ubuntuの標準VNCクライアントRemminaリモートデスクトップクライアント | ||
| + | |||
| + | === wget === | ||
| + | Proxy経由でwgetを実行する。 | ||
| + | |||
| + | ; ~/.wgetrcに以下を記述。 | ||
| + | |||
<pre> | <pre> | ||
| − | + | http_proxy=http://${xxx.xxx.xxx.xxx}:${pp}/ | |
| + | proxy_user=${user} | ||
| + | proxy_password=${pass} | ||
</pre> | </pre> | ||
| + | * ${xxx.xxx.xxx.xxx}:プロキシサーバのIPアドレス | ||
| + | * ${pp}:プロキシに利用するポート(基本的にはhttpのポート番号80を指定) | ||
| + | * ${user}:プロキシとして利用するユーザ | ||
| + | * ${pass}:${user}のパスワード | ||
| − | + | dl-box 192.168.11.3 | |
| + | |||
| + | == github == | ||
| + | |||
| + | プロキシ―環境にある場合は、プロキシ―サーバーをスルーする必要がある。 | ||
<pre> | <pre> | ||
| − | + | git config --global http.proxy http://proxy-a.t-kougei.ac.jp:8080 | |
| + | git config --global https.proxy https://proxy-a.t-kougei.ac.jp:8080 | ||
</pre> | </pre> | ||
| − | + | 通常のプロキシーのない環境で作業する場合、コンソールで | |
<pre> | <pre> | ||
| − | + | git config --global --unset http.proxy proxy.hogehoge.ac.jp | |
| + | git config --global --unset https.proxy proxy.hogehoge.ac.jp | ||
</pre> | </pre> | ||
| + | とする。 | ||
| − | + | 現在の設定を確認するには、コンソールで、 | |
| − | + | ||
<pre> | <pre> | ||
| − | + | git config --list | |
</pre> | </pre> | ||
| + | とする。 | ||
| − | + | == Chainer == | |
| + | MacOSで | ||
| − | + | * CUDA | |
| − | + | *opencv | |
| + | *deel | ||
| + | * CSLAIER http://localhost:8080 | ||
| + | <pre> | ||
| + | $ ./run.sh | ||
| + | </pre> | ||
| − | + | Chainerのインストール | |
| − | + | <pre> | |
| − | + | pip3 install chainer | |
| − | + | </pre> | |
| − | |||
| − | + | === 仕様の変更 === | |
| + | chainer.functionsがchainer.linksに変更 | ||
| + | <pre> | ||
| + | import chainer | ||
| + | from chainer.dataset import convert | ||
| + | from chainer import cuda | ||
| + | import chainer.functions as F | ||
| + | #import chainer.links as F | ||
| + | import chainer.link | ||
| + | import chainer.links | ||
| + | #from chainer.functions import caffe | ||
| + | from chainer.links import caffe | ||
| + | from chainer.links.caffe import CaffeFunction | ||
| + | from chainer import Variable, optimizers, Chain, cuda | ||
| + | </pre> | ||
2018年6月2日 (土) 00:55時点における版
目次 |
Chainer fast Neuralstyle
- 論文
- Justin Johnson, Alexandre Alahi, Li Fei-Fei, "Perceptual Losses for Real-Time Style Transfer and Super-Resolution"
- https://arxiv.org/abs/1603.08155
- 実装
- https://github.com/yusuketomoto/chainer-fast-neuralstyle
- https://github.com/gafr/chainer-fast-neuralstyle-models
- https://github.com/gafr/chainer-fast-neuralstyle-video
スタイル学習(モデルの生成)
- -sでスタイル画像
- -dでダウンロードしてきた画像集のフォルダを指定
- -rでリジューム
python train.py -s スタイル画像 -d 画像集フォルダ -r python train.py -s スタイル画像 -d train2014 -o 生成画像名 -r
クローン
git clone https://github.com/yusuketomoto/chainer-fast-neuralstyle.git
VGGのダウンロード。
wget http://www.robots.ox.ac.uk/~vgg/software/very_deep/caffe/VGG_ILSVRC_16_layers.caffemodel
chainer用に変換。
python create_chainer_model.py
A neural algorithm of Artistic style
http://arxiv.org/abs/1508.06576
chainer-gogh
https://research.preferred.jp/2015/09/chainer-gogh/
chainer-goghのインストール https://github.com/mattya/chainer-gogh.git
git clone https://github.com/mattya/chainer-gogh.git
学習済みモデルのダウンロード
- nin
wget https://www.dropbox.com/s/0cidxafrb2wuwxw/nin_imagenet.caffemodel
上記のコマンドとシェルスクリプトで。
source ~/dlmodel.sh
- vgg
caffemodel: VGG_ILSVRC_16_layers
chttp://www.robots.ox.ac.uk/~vgg/software/very_deep/caffe/VGG_ILSVRC_16_layers.caffemodel
処理は重いが、描画が綺麗。
chainer-gogh.pyの書式
python3 chainer-gogh.py [-m MODEL] -i CONTENS.jpg -s STYLE.jpg -o OUTPUT_DIR -g GPU_NUM [--width SIZE]
chainer-gogh.pyの実行例
python3 chainer-gogh.py -i sample_images/contents8.jpg -s sample_images/style.jpg -o save_images -g -1
例)元画像の重みを上げ、横幅460、イテレーション8000まで実行して作成する場合。
python chainer-gogh.py -m nin -i contents.png -s style.png -o output -g -1 --lam 0.8 --width 460 --iter 8000
- 最終的な画像サイズは512*512ピクセル以下に縮小
- コンテンツ画像はJPG または PNG
- コンテンツ画像は 500-1000ピクセル程度のサイズに
- スタイル画像も 500-1000ピクセル程度のサイズに
- オプションの値
parser = argparse.ArgumentParser(
description='A Neural Algorithm of Artistic Style')
parser.add_argument('--model', '-m', default='nin',
help='model file (nin, vgg, i2v, googlenet)')
parser.add_argument('--orig_img', '-i', default='orig.png',
help='Original image')
parser.add_argument('--style_img', '-s', default='style.png',
help='Style image')
parser.add_argument('--out_dir', '-o', default='output',
help='Output directory')
parser.add_argument('--gpu', '-g', default=-1, type=int,
help='GPU ID (negative value indicates CPU)')
parser.add_argument('--iter', default=5000, type=int,
help='number of iteration')
parser.add_argument('--lr', default=4.0, type=float,
help='learning rate')
parser.add_argument('--lam', default=0.005, type=float,
help='original image weight / style weight ratio')
parser.add_argument('--width', '-w', default=435, type=int,
help='image width, height')
args = parser.parse_args()
- GPU使用時のエラー
Traceback (most recent call last):
File "chainer-gogh.py", line 179, in <module>
cuda.get_device(args.gpu).use()
File "cupy/cuda/device.pyx", line 98, in cupy.cuda.device.Device.use
File "cupy/cuda/device.pyx", line 104, in cupy.cuda.device.Device.use
File "cupy/cuda/runtime.pyx", line 185, in cupy.cuda.runtime.setDevice
File "cupy/cuda/runtime.pyx", line 137, in cupy.cuda.runtime.check_status
cupy.cuda.runtime.CUDARuntimeError: cudaErrorUnknown: unknown error
これは、指定したGPUがないか使えないということ。ドライバーをインストールしなおしたら、解決した。
画風変換
python generate.py sample_images/コンテンツ元画像.jpg -m models/学習モデル.model -o sample_images/出力画像.jpg
- MacBook Pro CPU 3.3GHz Intel Core i7, 16GB, intel iris Graphics 550 1536MB : 15sec
CubistMirror
https://github.com/genekogan/CubistMirror
- oF0.10では,Pocoライブラリーが機能しない。
- v0.10では,PocoはAddonになった。v0.9以前は,本体に入っていた模様。
- QuickTime/QuickTime.h not found,には以下のものを使用。
neuralart TensorFlow
https://github.com/ckmarkoh/neuralart_tensorflow
環境設定
MacOSのLinuxで。
開発環境整備
- homebrew
- pnenv
- Phthon
- anaconda2
- anaconda3
- pip
Python3 とpip3のインストール
sudo apt install python3 python3-pip
Ubuntu
VNC
Ubuntuの標準VNCクライアントRemminaリモートデスクトップクライアント
wget
Proxy経由でwgetを実行する。
- ~/.wgetrcに以下を記述。
http_proxy=http://${xxx.xxx.xxx.xxx}:${pp}/
proxy_user=${user}
proxy_password=${pass}
- ${xxx.xxx.xxx.xxx}:プロキシサーバのIPアドレス
- ${pp}:プロキシに利用するポート(基本的にはhttpのポート番号80を指定)
- ${user}:プロキシとして利用するユーザ
- ${pass}:${user}のパスワード
dl-box 192.168.11.3
github
プロキシ―環境にある場合は、プロキシ―サーバーをスルーする必要がある。
git config --global http.proxy http://proxy-a.t-kougei.ac.jp:8080 git config --global https.proxy https://proxy-a.t-kougei.ac.jp:8080
通常のプロキシーのない環境で作業する場合、コンソールで
git config --global --unset http.proxy proxy.hogehoge.ac.jp git config --global --unset https.proxy proxy.hogehoge.ac.jp
とする。
現在の設定を確認するには、コンソールで、
git config --list
とする。
Chainer
MacOSで
- CUDA
- opencv
- deel
- CSLAIER http://localhost:8080
$ ./run.sh
Chainerのインストール
pip3 install chainer
仕様の変更
chainer.functionsがchainer.linksに変更
import chainer from chainer.dataset import convert from chainer import cuda import chainer.functions as F #import chainer.links as F import chainer.link import chainer.links #from chainer.functions import caffe from chainer.links import caffe from chainer.links.caffe import CaffeFunction from chainer import Variable, optimizers, Chain, cuda
Virtualbox
Oracle VM VirtualBoxで仮想マシン上にUbuntuを入れる。 https://www.virtualbox.org/
VirtualBoxで共有フォルダにアクセス権限がないとのエラーが出る場合は、以下の通り。
sudo gpasswd -a ユーザ名 vboxsf
Ubuntuのアップデート
sudo apt update
UbuntuAI
仮想マシンイメージUbuntuAIのダウンロード https://book.impress.co.jp/books/1116101162
タイプ Linux
バージョン Ubuntu(64bit)
メモリーサイズ 2048MB
ハードディスク すでにある仮想ハードディスクを使用する「UbuntuAI.vdi」
端末の起動 Alt+Cntl+T (Command+option+T)
TensorFlow
Work Station
NVIDIA Digits https://developer.nvidia.com/digits
大学生協対応PC http://www.univpc.com/product_list/cpu/74/99
参考
チームラボの勉強会