1 of 28

TensorFlow の 2 年間を�振り返る

@Tokushima University

2017-11-18

http://gcpug.jp

2 of 28

自己紹介

藤原 秀平 (FUJIWARA Shuhei)

@shuhei_fujiwara

  • 株式会社 TOPGATE 所属
  • Google Cloud Platform Authorized Trainer
  • TensorFlow User Group Organizer
  • GCPUG Tokyo Staff

http://gcpug.jp

3 of 28

今日の話

  • TensorFlow の話です

  • TensorFlow 2 年間の歴史を振り返りながら�機能や思想みたいなところを紹介します

  • 説明の都合上、時系列が若干前後しますが�ご了承ください

http://gcpug.jp

4 of 28

TensorFlow

Google が機械学習の実装に使用している

オープンソースのライブラリ

  • 2016-11-09 release
  • Google 検索の裏とかでも動いている(らしい)�すごいやつだ

http://gcpug.jp

5 of 28

リリース当初の TensorFlow

必要最低限の機能

  • 行列積など線型代数演算
  • 自動微分
  • GPU を使った演算
  • TensorBoard

http://gcpug.jp

6 of 28

最初にこれらの機能がリリースされた理由を察する

「これら + 分散処理」が TensorFlow の�根っこの部分

  • Deep Learning とかはその上に適宜実装すれば�良いよね

http://gcpug.jp

7 of 28

線型代数演算

import tensorflow as tf

�mat1 = tf.constant([[1, 2], [3, 4]])

mat2 = tf.constant([[2, 0], [0, 2]])

result = tf.matmul(mat1, mat2)

with tf.Session() as sess:

print(sess.run(result))

import numpy as np

mat1 = np.array([[1, 2], [3, 4]])

mat2 = np.array([[2, 0], [0, 2]])

result = np.dot(mat1, mat2)

print(result)

TensorFlow

NumPy

  • NumPy はこの時点で�行列積を計算

  • TensorFlow はまだ計算�していない
  • TensorFlow はこの時点で�初めて評価が行われる

http://gcpug.jp

8 of 28

Data Flow Graph

  • 予め計算の手順をグラフ構造で記述

constant

constant

matmul

constant

add

http://gcpug.jp

9 of 28

Data Flow Graph

  • 後からノードを選んで明示的に実行
  • 依存関係のある部分が遅延評価される

constant

constant

matmul

constant

add

Run

http://gcpug.jp

10 of 28

自動微分

  • Deep Learning は関数が複雑なので微分を人間が計算して�実装するのが結構しんどい

  • 自動で微分するためには�計算の手順が何らかの形で残っている必要がある

Data flow graph の必要性

http://gcpug.jp

11 of 28

複数デバイスの活用

  • 複数の GPU や CPU を簡単に扱える

  • データの送受信の処理が勝手に最適化されて�data flow graph に追加される

  • クラスタのノード間通信も�同様

http://gcpug.jp

12 of 28

Demo: TensorBoard

  • Data flow graph の特定のノードを見張る
  • Data flow graph を可視化する

http://gcpug.jp

13 of 28

このとき我々が待ち望んていたもの

  • 行列演算レベルからアルゴリズムを実装するのは�結構しんどい

x_ph = tf.placeholder(tf.float32, [None, 784])�y_ph = tf.placeholder(tf.float32, [None, 10])

weights = tf.Variable(tf.random_normal([784, 20], stddev=0.1))

biases = tf.Variable(tf.zeros([20]))

hidden = tf.matmul(x_ph, weights) + biases

weights = tf.Variable(tf.random_normal([20, 10], stddev=0.1))

biases = tf.Variable(tf.zeros([10]))

logits = tf.matmul(hidden, weights) + biases

�y = tf.nn.softmax(logits)

http://gcpug.jp

14 of 28

高レベル API の整備が始まる

  • 行列演算などを隠蔽
  • ニューラルネットのパーツ単位で記述できるように

x_ph = tf.placeholder(tf.float32, [None, 784])�y_ph = tf.placeholder(tf.float32, [None, 10])

hidden = tf.layers.dense(x_ph, 20)�logits = tf.layers.dense(hidden, 10)�y = tf.nn.softmax(logits)

http://gcpug.jp

15 of 28

このとき我々が待ち望んでいたもの

  • 論文には大規模分散処理の機能が書かれているけど�まだ実装されていない

  • TensorFlow の目玉機能

http://gcpug.jp

16 of 28

満を持して Distributed TensorFlow が登場

  • そこそこ簡単に分散学習

  • 勾配の計算を並列化

  • クラスタのノードを�増やして高速化できる

mini-batch samples

Compute grad.

grad.

grad.

sum

Share

Update

http://gcpug.jp

17 of 28

このとき我々が待ち望んでいたもの

分散学習の環境構築するのめんどい

http://gcpug.jp

18 of 28

Cloud Machine Learning Engine の登場

  • 分散学習の環境が手軽に用意できるように

  • この頃から Google Cloud Platform との連携が始まる
    • 実はこれまで TensorFlow と GCP は�何の関係もなかった

http://gcpug.jp

19 of 28

このとき我々が待ち望んでいたもの

ところで GCP にGPU インスタンス無いんだけど

http://gcpug.jp

20 of 28

Google Cloud Platform に GPU インスタンスが登場

  • Compute Engine と Cloud ML Engine で使用可能

  • 実は今まで皆 TensorFlow で GPU 使いたいときは�オンプレか AWS で回してた

  • でも同時に Google Cloud Spanner が出たので�話題を持ってかれた

http://gcpug.jp

21 of 28

ひっそりと強化される Cloud Storage との連携

  • ローカルのファイルシステムと Cloud Storage を�同様に扱えるように

  • TensorBoard で Cloud Storage のファイルを扱えるように

http://gcpug.jp

22 of 28

このとき我々が待ち望んでいたもの

分散学習実装するの若干めんどい

http://gcpug.jp

23 of 28

さらに強化される高レベル API

  • アルゴリズムの詳細がわからなくても実装できるように
  • コードを変えずに分散学習が可能に

classifier = tf.estimator.DNNClassifier(

feature_columns=[tf.feature_column.numeric_column("x", shape=[4]),

hidden_units=[10, 20, 10],

n_classes=3,

model_dir="/tmp/iris_model"

)

http://gcpug.jp

24 of 28

Tensor Processing Unit (TPU)

  • TensorFlow 専用のプロセッサ

  • 近々 GCP 上で使えるようになる予定

http://gcpug.jp

25 of 28

TensorFlow のこれから(個人的な予想)

TensorFlow の用途は Deep Learning だけじゃない

TensorFlow の根っこの部分は

線形代数演算 x 分散処理 x 自動微分 x GPU (と TPU) の活用

この上にどんなアルゴリズムを実装するかは開発者の自由!

http://gcpug.jp

26 of 28

TensorFlow のこれから(個人的な予想)

実際 Deep Learning 以外にも様々なアルゴリズムが�実装され始めている

  • カーネル法
  • Random Forest
  • etc...

http://gcpug.jp

27 of 28

まとめ

  • ここ 2 年間で TensorFlow はかなり使いやすくなった
    • 高レベル API の整備
    • 分散学習など大規模な学習をそこそこ手軽に

  • GCP との連携が大幅に強化された
    • Cloud ML Engine で簡単に�GPU + 分散学習用クラスタが手に入る

  • 進化していく TensorFlow と GCP を眺めるの楽しいよ!

http://gcpug.jp

28 of 28

TensorFlow や GCP に興味がある人へ

ぜひコミュニティに参加してください!

  • Google Cloud Platform User Group
    • https://gcpug.jp/join

  • TensorFlow User Group

TFUG Shikoku を作るのは君だ

http://gcpug.jp