Deep Learning

提供:kuhalaboWiki
移動: 案内, 検索

目次

PaintsChainer

https://github.com/pfnet/PaintsChainer

https://qiita.com/ikeyasu/items/6c1ebed07b281281b1f6

Generative Music

AdaIN
styleGANに使われている。

深層学習は、精製モデルと認識も出るの両輪で発展。生成モデル制御は両方にかかわる。

VAE

memo

w3

CentOS Linux release 7.5.1804 (Core)

www

CentOS release 6.8 (Final)


MacOSX

command line developer toolsのインストール
$ xcode-select --install

開発環境整備

homebrew

Homebrew をダウンロード・インストール http://brew.sh/index_ja.html

  • pnenv
  • Phthon
    • anaconda2
    • anaconda3
  • pip

oF

openFrameworks

https://openframeworks.cc/setup/linux-install/

Ubuntu

Python3 とpip3のインストール
sudo apt install python3 python3-pip
PILライブラリのインストール
sudo pip install pillow

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

アプリ自動起動

  • sessionにて指定する。

自動シャットダウン

cronを使用する。

エディターを開く。

$sudo crontab -e

一番最後の行に以下の記述を追加する。

30 22 * * * /sbin/shutdown -h now

毎日22:30にシャットダウンするという意味。

保存して、エディターを閉じる。

  • 保存 [Ctrl] + o
  • 閉じる [Ctrl] + x

設定を確認する。

$crontab -l
端末の起動
Alt+Cntl+T (Command+option+T)

Python

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」

画像処理

Pythonでの画像処理

  • Numpy 高速数値演算
  • Pillow 画像処理
  • OpenCV コンピュータビジョン

OpenCVではカラー画像はBGRで表す歴史的背景 Why does OpenCV use BGR color format ?

BGRからRGBへの変換

img_rgb = img_bgr[:,:,::-1].copy()

RGBからBGRへの変換

img_bgr = img_rgb[:,:,::-1].copy()

Pythonのスライス「第1, 2次元目はそのままで、第3次元目は逆方向に並べたもの」


PythonのopenCVでフルスクリーンにする方法

cv2.namedWindow("screen", cv2.WINDOW_NORMAL)
cv2.setWindowProperty('screen', cv2.WND_PROP_FULLSCREEN, 1)
cv2.imshow('screen', img)

フルスクリーンを解除するには

cv2.setWindowProperty('screen', cv2.WND_PROP_FULLSCREEN, 0)

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
実装
Training画像データ

スタイル学習(モデルの生成)

  • -sでスタイル画像
  • -dでダウンロードしてきた画像集のフォルダを指定
  • -rでリジューム
python train.py -s スタイル画像 -d 画像集フォルダ -r
python train.py -s スタイル画像 -d train2014 -o 生成モデル名 -r
train.pyの修正
#    image = image.crop(((w-size)*0.5, (h-size)*0.5, (w+size)*0.5, (h+size)*0.5))
    image = image.crop((int((w-size)*0.5), int((h-size)*0.5), int((w+size)*0.5), int((h+size)*0.5)))

クローン

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


画風変換

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
  • GeForce GTX 1080 Ti (CNMeM is enabled with initial size: 50.0% of memory, cuDNN 5105) : 0.856794118881 sec
  • Xeon E5-1620v4 4core/8thread 3.5GHz, 64GB : 8.52293109894 sec

CubistMirror

oFでUbuntuのchainerを動かす。

https://openframeworks.cc/

LinuxでのoF

make
make run

https://github.com/genekogan/CubistMirror

  • oF0.10では,Pocoライブラリーが機能しない。
    • v0.10では,PocoはAddonになった。v0.9以前は,本体に入っていた模様。
  • QuickTime/QuickTime.h not found,には以下のものを使用。
外部カメラを接続する場合
 // ofApp.h
    ofVideoGrabber grab;

//ofApp.cpp setup()
    // set up camera
    ofSetLogLevel(OF_LOG_VERBOSE); 
    grab.setVerbose(true);
    grab.listDevices();    
    grab.setDeviceID(1);// camera ID set   

A neural algorithm of Artistic style

http://arxiv.org/abs/1508.06576

A Neural Algorithm of Artistic Style

Leon A. Gatys, Alexander S. Ecker, Matthias Bethge (Submitted on 26 Aug 2015 (v1), last revised 2 Sep 2015 (this version, v2))

chainer-gogh

画風を変換するアルゴリズム(Preferred Networks(PFN)松元叡一氏) 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

wget http://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()


仕様の変更

  • 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
  • volatileとtrainオプションがなくなったので、*.pyソース内の引数を削除


  • 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がないか使えないということ。ドライバーをインストールしなおしたら、解決した。

neuralart TensorFlow

https://github.com/ckmarkoh/neuralart_tensorflow

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で

$ ./run.sh

Chainerのインストール

pip3 install chainer

TensorFlow

PyTorch

https://pytorch.org/tutorials/advanced/neural_style_tutorial.html

Work Station

NVIDIA Digits https://developer.nvidia.com/digits

大学生協対応PC http://www.univpc.com/product_list/cpu/74/99

ノート型 https://www.pc-koubou.jp/pc/deeplearning_pc.php?pre=cmm_hnv_019

参考

絵画風動画変換

箱根にあるとある水車小屋 https://youtu.be/3MwTQJrDCeo

ローマの休日 https://youtu.be/F5RTxOr0_Cw

物体検出

http://ai-coordinator.jp/category/object-detection


AI Artistic Neuro Painter

http://www.kuhalabo.net/aipaint/

http://www.kuhalabo.net/aipaint/iframe.html

個人用ツール
名前空間

変種
操作
案内
ツールボックス