Top Banner
深層学習ライブラリの 現在 2015-10-24 @WebTokyoMining 1
70

Deep learning Libs @twm

Apr 14, 2017

Download

Technology

Yuta Kashino
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Deep learning Libs @twm

深層学習ライブラリの 現在

2015-10-24 @WebTokyoMining

1

Page 2: Deep learning Libs @twm

今日の内容• 自己紹介

• 深層学習 学習リソース

• 神経回路網と実装

• 深層学習ライブラリ

• 主要深層学習ライブラリの特徴

• モデル実装の違い2

Page 3: Deep learning Libs @twm

自己紹介

3

Page 4: Deep learning Libs @twm

自己紹介• バクフー株式会社 代表取締役 柏野 雄太 (かしの ゆうた)

• 大規模リアルタイムデータのデータプラットフォーム

• PPPP preprocess /process /persistence /providing

4

Page 5: Deep learning Libs @twm

http://socio.bakfoo.com/[email protected]

Closed Beta

Page 6: Deep learning Libs @twm

自己紹介• 大規模リアルタイムのデータプラットフォーム

リアルタイムデータ 前処理 処理 ストア 提供

tweets 整形 自然言語処理・分類 API, 検索, 可視化

気象データ 変換 分類・異常値検知 API, 検索,ストリーミング

位置データ 変換 分類 API, 検索, ストリーミング

経済データ 整形・変換 異常値検知 API, 検索, 可視化6

Page 8: Deep learning Libs @twm

ご注意

8

Page 9: Deep learning Libs @twm

本日のターゲット層• PyLearn2やCaffeやChainerなどのexampleを動作させたけれど,その後どうすればわからない人

• 岡谷本を読んだけれど,結構目が泳いでしまった人

• Model Zooの学習済みモデルしか利用したことの無い人

9

Page 10: Deep learning Libs @twm

このトークで話さないこと• モデルを沢山だしません

• 最新の学術的トピックもだしません

• Dropout, Whitening, Batch Normalisation, Maxoutなど重要ですがややこしくなるものは割愛します

• モデルの評価,グリッドサーチ,計算機実験の話もしません

• シンギュラリティや「人工知能」の話もしません10

Page 11: Deep learning Libs @twm

深層学習ライブラリ狂騒• 2014年から2015年の前半,毎週のように新しい深層学習ライブラリが話題に

• 新しいライブラリの出現は最近はピークアウトしています

• 今回のトークを申し出た時期は,狂騒的な時期でした

• 状況が変化していますので,話す内容も少し汎用的なものにします.

11

Page 12: Deep learning Libs @twm

DLのモデリングができる

深層学習の基礎を取得済み

12

Page 13: Deep learning Libs @twm

深層学習 学習リソース

13

Page 14: Deep learning Libs @twm

動画講義 (全力でオススメ)

• Deep Learning Summer School 2015

• Hugo Larochelle (Twitter/U of Sherbrooke)

• Nando de Freitas (Oxford)

• CS231n: CNN for Visual Recognition

• CS224d: DL for Natural Language Processing

http://videolectures.net/deeplearning2015_montreal/

http://cs231n.stanford.edu/

http://cs224d.stanford.edu/index.html

https://www.cs.ox.ac.uk/people/nando.defreitas/machinelearning/

https://goo.gl/UWtRWT

14

Page 15: Deep learning Libs @twm

書籍• 古典: Bengio et.al. 2015 DLBook

• Theano Tutorial

• Neural Networks and Deep Learning

• 岡谷貴之著 深層学習 (機械学習プロ)

• 神嶌敏弘編 深層学習: Deep Learning

http://www.iro.umontreal.ca/~bengioy/dlbook/

http://neuralnetworksanddeeplearning.com/

http://deeplearning.net/tutorial/deeplearning.pdf

15

Page 16: Deep learning Libs @twm

神経回路網と実装

16

Page 17: Deep learning Libs @twm

神経回路の数理表現

17

h

(k)(x) = g(a(k)(x))

a

(k)(x) = b

(k) +W

(k)h

(k�1)(x)

…1

1

1b(3)

b(2)

b(1)W (1)

W (2)

W (3)

x1 x2 xd

a

(3)(x) = b

(3) +W

(3)h

(2)(x)

= b

(3) +W

(3)g(b(2) +W

(2)h

(1)(x))

= b

(3) +W

(3)g(b(2) +W

(2)g(b(1) +W

(1)x))

h

(0)(x) = x

h

(1)(x) = g(a(1)(x))

h

(2)(x) = g(a(2)(x))

a

(1)(x) = b

(1) +W

(1)h

(0)(x)

a

(2)(x) = b

(2) +W

(2)h

(1)(x)

a

(3)(x) = b

(3) +W

(3)h

(2)(x)

h

(3)(x) = o(a(3)(x))

= f(x)

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)

W (2)

W (3)

x

Page 18: Deep learning Libs @twm

マルチレイヤー神経回路• L個の隠れ層の神経回路

• プレ活性

• 隠れ層活性

• 出力層活性

• レイヤーは関数適用に他ならない

18

h

(k)(x) = g(a(k)(x))

a

(k)(x) = b

(k) +W

(k)h

(k�1)(x)

h

(L+1)(x) = o(a(L+1)(x))

= f(x)

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)

W (2)

W (3)

x

Page 19: Deep learning Libs @twm

機械学習と損失関数• パラメータ・トレーニングセット

• 目的関数最小化

• 損失関数・正則関数a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)

W (2)

W (3)

x

l(f(x), y)

✓ = {W (1), b(1), ...,W (L+1), b(L+1)}

(x(t), y(t))

⌦(✓)

l(f(x(t);✓), y(t)) = �logf(x(t)

)y

L(✓) =1

T

X

t

l(f(x(t);✓), y(t)) + �⌦(✓)

argmin✓L(✓)

19

Page 20: Deep learning Libs @twm

勾配降下と確率的勾配降下• 目的関数Lを最小化:勾配の方向にθを動かす

• 確率的勾配降下:ミニバッチ t だけをみて勾配計算

� = �r✓l(f(x(t);✓), y(t))

✓ ✓ + ↵�

Lの等高線

α: 学習率

20

Page 21: Deep learning Libs @twm

勾配の計算:誤差逆伝搬• 目的関数を最小にするには勾配の計算が必要

• 勾配の計算=誤差逆伝搬 � = �r✓l(f(x(t);✓), y(t))

✓ ✓ + ↵�

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

rW

(2) l(f(x), y) ra

(2)(x)l(f(x), y)h(2)(x)T

ra

(2)(x)l(f(x), y) rh

(2)(x)l(f(x), y)� [..., g0(a(2)(x)), ...]

rh

(2)(x)l(f(x), y) W

(3)Tra

(3)(x)l(f(x), y)

21

Page 22: Deep learning Libs @twm

勾配の計算:誤差逆伝搬• Hugo Larochelleの講義にGo https://goo.gl/UWtRWT

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

rW

(2) l(f(x), y) ra

(2)(x)l(f(x), y)h(2)(x)T

ra

(2)(x)l(f(x), y) rh

(2)(x)l(f(x), y)� [..., g0(a(2)(x)), ...]

rh

(2)(x)l(f(x), y) W

(3)Tra

(3)(x)l(f(x), y)

22

Page 23: Deep learning Libs @twm

勾配の計算:誤差逆伝搬• 主要DLライブラリは勾配を自動に計算 • 実はあまり気にしないでいい

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

l(f(x), y)

rW

(2) l(f(x), y) ra

(2)(x)l(f(x), y)h(2)(x)T

ra

(2)(x)l(f(x), y) rh

(2)(x)l(f(x), y)� [..., g0(a(2)(x)), ...]

rh

(2)(x)l(f(x), y) W

(3)Tra

(3)(x)l(f(x), y)

23

Page 24: Deep learning Libs @twm

ライブラリ利用で必要なのは• データを入れる場所:テンソル • レイヤーの表現 • 活性化関数・出力関数 • 損失関数 • 最適化法 • 勾配計算(誤差伝搬)

• GPUへの対応

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

g

g

o

b(1)W (1)

b(3)

b(2)

W (2)

W (3)

x

l(f(x), y)

24

Page 25: Deep learning Libs @twm

深層学習ライブラリ

25

Page 26: Deep learning Libs @twm

DLライブラリ@GitHub

• GitHubにあるWatcherが二人以上 2015-10-20

• “deep learning” : 393

• “theano”: 239

• “caffe”: 281

• 多すぎて全部フォローなどできません.

26

Page 27: Deep learning Libs @twm

DLライブラリ@GitHub

• “deep learning”をライブラリ別にみると…

27

Page 28: Deep learning Libs @twm

DLライブラリ@GitHub

• “deep learning”を言語別にみると…

28

Page 29: Deep learning Libs @twm

DLライブラリ@GitHub

• “theano”をライブラリ別にみると…

29

Page 30: Deep learning Libs @twm

深層学習汎用ライブラリ

• 汎用ライブラリ(General Purpose) =色々なモデルを構築できる OverFeatのようにCNN特化でなく

• オープンソースである.

• 開発が継続中である.

30

Page 31: Deep learning Libs @twm

DLライブラリ世代論• 第一世代: GPU対応

• Theano, Torch

• 第二世代: プレトレーニングモデル利用 DIY時代

• Caffe, PyLearn2

• 第三世代: より使いやすく,より速くmulti-GPU

• Keras, Lasagne, Chainer, Neon

31

Page 32: Deep learning Libs @twm

主要ライブラリ7つ

• Theano

• Torch7

• Caffe

• Keras

• Lasagne

• Chainer

• Neon

32

Page 33: Deep learning Libs @twm

主要深層学習 ライブラリの特徴

33

Page 34: Deep learning Libs @twm

Theano• James Bergstra+ (montreal/Bengio) • Python/Cython • GPU:独自(CUDA/cuDNN)

• DLライブラリの草分け

• 強力な自動微分機能,NumPyとシームレス

• 独自のPython → C変換で高速

• 数々のDLライブラリのビルディングブロックに

• 益々開発が活発になっている

https://github.com/Theano/Theano

34

Licence multiGPU Binding ActivityBSD △ ◎

Page 35: Deep learning Libs @twm

Torch7• Ronan Collobert (FB AI), Koray Kavukcuoglu (G

DeepMind), Clement Farabet (Twitter)

• GPU: cutorch (CUDA/cuDNN/OpenMP)

• Model: Lua

• Matlab風のコーディングをLuaでする

• Lua.JITでCになるので高速

• 拡張性が高い →ライブラリが充実

• 全然現役

http://ronan.collobert.com/pub/matos/2011_torch7_nipsw.pdf

https://github.com/torch/torch7

35

Licence multiGPU Binding ActivityBSD ○ C/C++ ◎

Page 36: Deep learning Libs @twm

Caffe• Yangqing Jia (Google)

• GPU: 独自(CUDA/cuDNN)

• Model:Protocol Buffer

• モデルプログラムをさせない: ”DIY DL for Vision"

• Model Zoo, Reference models

• 最近元気がない…

https://github.com/BVLC/caffe/

36

Licence multiGPU Binding ActivityBSD - python/matlab △

Page 37: Deep learning Libs @twm

Keras• François Chollet (Google)

• GPU: Theano

• Model: Python

• クリーンでクリアなモデリング

• Theanoを隠蔽.Theanoの内部データはとれない:ある層の勾配

• 人気が急上昇中

https://github.com/fchollet/keras

37

Licence multiGPU Binding ActivityMIT △ O

Page 38: Deep learning Libs @twm

Lasagne• Sander Dieleman (G DeepMind)

• GPU: Theano

• Model: Python

• Theano + layer + activ./loss func + optimizer

• 最後には必ずTheanoを触る必要がある

• Theano好きには○,ただ最近元気がない

https://github.com/torch/torch7

38

Licence multiGPU Binding ActivityMIT △ △

Page 39: Deep learning Libs @twm

Chainer• 得居誠也 (PFI/PFN)

• GPU: cupy (CUDA, cuDNN) 以前はPyCUDA

• Model: Python

• 動的グラフなど設計思想が違う革命児

• ギリギリまでPythonオブジェクトなのでデバグが異常に楽

• PFI/PFNの主力兵器になる可能性

https://github.com/pfnet/chainer

http://www.ustream.tv/recorded/64082997http://goo.gl/z2IjsY

39

Licence multiGPU Binding ActivityMIT ○ ◎

Page 40: Deep learning Libs @twm

Neon• Arjun Bansal+ (Nervana Systems) G/Fでない…

• GPU: PyCUDAベースの独自

• Model: Python

• 関数・レイヤーなど良く整備され準備されたAPI群を装備

• シングルマシンにおいて汎用DLライブラリ最速

https://github.com/nervanasystems/neon

40

Licence multiGPU Binding ActivityApache ○ ○

https://github.com/soumith/convnet-benchmarks

Page 41: Deep learning Libs @twm

Reference Manual / Code

• ライブラリを使うには

• Exampleの後は,Reference Manual熟読しましょう.設計思想がわかります.

• そしてソースコードを読みましょう.

41

Page 42: Deep learning Libs @twm

モデル実装の違い

42

Page 43: Deep learning Libs @twm

実装するモデルの例• MNISTデータ

• MLP(Multi Layer Perception) 隠れ層 2つ

43

http://deeplearning.net/tutorial/mlp.html

a

(1)(x)

a

(2)(x)

a

(3)(x)

h

(2)(x)

h

(1)(x)

f(x) = h

(3)(x)

b(1)W (1)

b(3)

b(2)

W (2)

W (3)

x

o: softmax

g: ReLU

g: ReLU

Page 44: Deep learning Libs @twm

Theano https://github.com/Theano/Theano

44

事前設定

Page 45: Deep learning Libs @twm

Theano https://github.com/Theano/Theano

45

活性化関数,損失関数,レイヤー定義

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

o: softmax

g: ReLU

g: ReLU

Page 46: Deep learning Libs @twm

Theano https://github.com/Theano/Theano

46

ネットワーク・グラフ構築+学習

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

o: softmax

g: ReLU

g: ReLU

Page 47: Deep learning Libs @twm

Theano https://github.com/Theano/Theano

47

まとめ

テンソル theano.tensor

レイヤー -

モデル構築 高階関数で連鎖させる

活性化関数 theano.tensor.nnet

損失関数 theano.tensor.nnet

最適化 -

勾配計算 theano.gradient

GPUマップ shared, function

その他

Page 48: Deep learning Libs @twm

Torch7 https://github.com/torch/torch7

48

事前設定+ネットワーク・グラフ構築

Page 49: Deep learning Libs @twm

Torch7 https://github.com/torch/torch7

49

損失関数+学習ループ

Page 50: Deep learning Libs @twm

Torch7 https://github.com/torch/torch7

50

まとめ

テンソル torch.Tensor

レイヤー nnの”SimpleLayers”

モデル構築 nnの"Containers"にaddしていく

活性化関数 nnの"Transfer functions"

損失関数 nnの"Criterions"

最適化 optim

勾配計算 nnの"Criterions"のbackwardメソッド

GPUマップ cutorch他

その他

Page 51: Deep learning Libs @twm

Caffe https://github.com/BVLC/caffe/

51

ネットワーク・グラフ構築

Page 52: Deep learning Libs @twm

Caffe https://github.com/BVLC/caffe/

52

学習

Page 53: Deep learning Libs @twm

Caffe https://github.com/BVLC/caffe/

53

まとめ

テンソル Blobs (ndarrayと互換性がある)

レイヤー Layers

モデル構築 protcol bufferにレイヤーを一層一層グラフ構成

活性化関数 Activation/Neuron Layers これもレイヤー

損失関数 Loss

最適化 Solver

勾配計算 Solverが自動で逆誤差伝搬

GPUマップ CUDAドライバのフラグをみて勝手に

その他

Page 54: Deep learning Libs @twm

Keras https://github.com/fchollet/keras

54

事前設定

Page 55: Deep learning Libs @twm

Keras https://github.com/fchollet/keras

55

ネットワーク・グラフ構築+学習

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

o: softmax

g: ReLU

g: ReLU

Page 56: Deep learning Libs @twm

Keras https://github.com/fchollet/keras

56

まとめ

テンソル numpy.ndarray, theano.tensor

レイヤー keras.layers

モデル構築 keras.modelsオブジェクトにaddしていく

活性化関数 keras.layers.core

損失関数 keras.layers.core

最適化 keras.optimizers

勾配計算 Theano(Kerasからは見えない)

GPUマップ Theano

その他

Page 57: Deep learning Libs @twm

Lasagne https://github.com/torch/torch7

57

ネットワーク・グラフ構築

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

o: softmax

g: ReLU

g: ReLU

Page 58: Deep learning Libs @twm

Lasagne https://github.com/torch/torch7

58

損失関数・最適化手法

Page 59: Deep learning Libs @twm

Lasagne https://github.com/torch/torch7

59

まとめ

テンソル theano.tensor

レイヤー lasagne.layers

モデル構築 lasagne.layersオブジェクトを高階関数で連鎖させる

活性化関数 lasagne.layers

損失関数 lasagne.objectives

最適化 lasagne.updates

勾配計算 Theano(Lasagneからは見えない)

GPUマップ Theano

その他

Page 60: Deep learning Libs @twm

Chainer https://github.com/pfnet/chainer

60

事前設定

Page 61: Deep learning Libs @twm

Chainer https://github.com/pfnet/chainer

61

ネットワーク・グラフ構築

b(1)W (1)

b(3)

b(2)W (2)

W (3)

x

o: softmax

g: ReLU

g: ReLU

Page 62: Deep learning Libs @twm

Chainer https://github.com/pfnet/chainer

62

学習ループ

Page 63: Deep learning Libs @twm

Chainer https://github.com/pfnet/chainer

63

まとめ

テンソル chainer.Variable (勾配情報なども.ndarrayの拡張的な)

レイヤー chainer.Function

モデル構築 高階関数の連鎖でgraphをつくる.

活性化関数 chainer.functions

損失関数 chainer.functions

最適化 chainer.Optimizer

勾配計算 chainer.Function.backward()

GPUマップ Function.to_gpu(), chainer.cuda.to_gpu

その他

勾配情報を保持したいときはcainer.FunctionSetにまとめて格納

Page 64: Deep learning Libs @twm

Neon https://github.com/nervanasystems/neon

64

事前設定

Page 65: Deep learning Libs @twm

Neon https://github.com/nervanasystems/neon

65

ネットワーク・グラフ構築

Page 66: Deep learning Libs @twm

Neon https://github.com/nervanasystems/neon

66

学習

Page 67: Deep learning Libs @twm

Neon https://github.com/nervanasystems/neon

67

まとめ

テンソル numpy.ndarray

レイヤー neon.layers

モデル構築 neon.layersを選びリストに追加.neon.models.Modelに

活性化関数 neon.transforms.activation

損失関数 neon.transforms.cost

最適化 neon.optimizers

勾配計算 neon.backends.autodiff

GPUマップ

その他

Page 68: Deep learning Libs @twm

パフォーマンス• AlexNet (One Weird Trick paper) - Input 128x3x224x224

https://github.com/soumith/convnet-benchmarks

68

Page 69: Deep learning Libs @twm

まとめ• 深層学習ライブラリは第三世代.どれも甲乙つけがたい.第一世代も現役.

• ライブラリを利用する前に,深層学習の基礎を学びましょう

• ライブラリを利用するにはリファレンスを熟読してソースコードを読みましょう

69

Page 70: Deep learning Libs @twm

ご質問・ご意見

[email protected]

70

@yutakashino