Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Oracle Code Tokyo 2019 資料 / GraphPipe and TensorFlow, Serverless and Neural Networks with Fn Project

Oracle Code Tokyo 2019 資料 / GraphPipe and TensorFlow, Serverless and Neural Networks with Fn Project

Oracle Code Tokyo 2019 の標題のセッションで使用した資料です。
https://www.oracle.co.jp/events/code/2019/

資料最後のQRコードが示すURLは以下です。
https://blogs.oracle.com/bigdata-dataintegration-jp/graphpipe_intro

Miki Kawauchi

May 17, 2019
Tweet

More Decks by Miki Kawauchi

Other Decks in Technology

Transcript

  1. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | GraphPipe and TensorFlow, Serverless and Neural Networks with Fn Project 日本オラクル株式会社 ソリューションエンジニアリング統括 クラウドプラットフォーム本部 河内 美樹 2019/05/17
  2. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | 2 以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するものです。 また、情報提供を唯一の目的とするものであり、いかなる契約にも組み込むことはできません。以 下の事項は、マテリアルやコード、機能を提供することをコミットメント(確約)するものではない ため、購買決定を行う際の判断材料になさらないで下さい。オラクル製品に関して記載されてい る機能の開発、リリースおよび時期については、弊社の裁量により決定されます。 OracleとJavaは、Oracle Corporation 及びその子会社、関連会社の米国及びその他の国における登録商標です。 文中の社名、商品名等は各社の商標または登録商標である場合があります。
  3. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | 機械学習における学習と推論 3 教師あり学習で分類問題を解く場合 ✔ ネコ ✔ イヌ ✔ ウサギ 推論 これは何? 大量データ(ラベル有り) 新しいデータを モデルに適用し予測する ネコかな? 学習 学習済みのモデル 大量データ(ラベル有り) を使って機械学習
  4. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | 機械学習における推論(モデルの提供) • 教師あり機械学習における学習(Train)と推論(Inference) – 学習:大量のラベルありデータから学習することで、モデルを構築する – 推論:学習済みのモデルを、新規データ(未知のデータ)に適用し予測する • 機械学習のモデル構築は、TensorFlowやPyTorchなどオープンソース フレームワークによって、開発しやすくなってきている • 機械学習(ML)で推論を行うときに、クライアントからアクセスして 利用できるよう、サーバ上に学習済みのモデルを利用可能な形で提供する – ML Clientと ML Serverの2つのコンポーネント 4
  5. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | GraphPipeを使わない場合 5 それぞれの フレームワーク固有の フォーマットでのモデル提供 クライアントからは それぞれのフレームワーク固有の Call方法
  6. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | GraphPipeとは • 学習済みのモデルを扱うためのプロトコルを定義し、サーバとクライアントを提供、 オープンソースとして公開している – ネットワーク経由でテンソルデータを送信するための標準的なプロトコルを定義 – そのプロトコルに準じたモデルを呼び出し可能な形で提供するようなサーバの実装 – GraphPipe経由でモデルをCallするためのクライアントライブラリ 7 Graphpipe無し Graphpipe有り • Call方法がバラバラ • サーバ構築が難しい • 性能面での課題 • APIの標準化 • 高い性能
  7. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | GraphPipeの特長 • プロトコル定義と標準化 – APIでCall可能、開発言語が違っても良い – マイクロサービス化しやすい、部分的な改修に対応しやすい • 高速 – GraphPipeではフラットバッファ形式で扱う – 特に、デシリアライズ面で優位性のあるアーキテクチャ 8
  8. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | GraphPipeの特長:高速 9 出典:https://blogs.oracle.com/developers/introducing-graphpipe
  9. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | GraphPipeを使ったアプリケーション:学習 10 画像認識するモデルを生成する import tensorflow as tf import … … # エクスポート用のグラフを生成する g = tf.Graph() with g.as_default(): x = tf.placeholder(…) … graph_def = g.as_graph_def() tf.train.write_graph(graph_def, './tmp/outputdir','model.pb', as_text=False) 学習済みのモデルを GraphPipeが対応する フォーマットで保存する 画像を認識するモデルを作成し、学習済みのモデルをエクスポートする ※学習時はgraphpipeライブラリは不要
  10. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | GraphPipeを使ったアプリケーション:推論 11 学習済みのモデルを装備し、クライアントからの要求に応える … from graphpipe import remote … 画像ファイルを事前処理する img := 画像ファイルを事前処理したもの pred = remote.execute("http://server:port", img) print(np.argmax(pred, axis=1)) $ docker run -it --rm -v "$(pwd)/models:/models/" -p 127.0.0.1:9000:9000 sleepsonthefloor/graphpipe-tf:cpu --model=/models/model.pb --listen=0.0.0.0:9000 入力を渡す 予測結果を返す テンソルデータ テンソルデータ ML Client ML Server GraphPipeライブラリをimportしてCall model= で学習済みのモデルを指定して graphpipeのDockerコンテナを起動する
  11. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | GraphPipe:対応するフレームワークとフォーマット • TensorFlow – SavedModel フォーマット – GraphDef(.pb)フォーマット: protobufとしてシリアライズされたgraphdef • Kerasモデルを使用している場合、生成するのが最も簡単なフォーマット • keras .h5 をGraphDef .pbフォーマットに変換するためのツールを graphpipe-tf-py リポジトリで提供している • Caffe2 / ONNX / PyTorch – ONNX(.onnx)+ value_inputs.json – Caffe2 NetDef + value_inputs.json • GraphPipe Server – TensorFlow用、ONNX用 それぞれの docker Image • GraphPipe Client API – Python, Go 用のAPI 12 詳細:https://oracle.github.io/graphpipe/#/
  12. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | AIの活用 13 さまざまな産業や分野で活用されてきている 出典: 2019/05/09 @IT 川崎重工がエッジAIを活用する理由 https://www.atmarkit.co.jp/ait/articles/1905/08/news001.html 駅での「戸挟み検知」 (電車のドアに物がはさまる) 自動運転 医療画像診断 不正取引の検出 故障予測
  13. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | エッジ側で推論する • 背景となる要件 – セキュリティの制約上、データを外に持ち出せない – データ容量が大きく、ネットワーク転送に適さない – ネットワークレイテンシが許されないようなリアルタイム性が求められる • 軽量なモデルが望ましい – 利用可能なハードウェアリソースや処理能力に制約があることが多い – 推論で使うモデルは軽いことが望まれる 例):精度よりも速度を優先する 14
  14. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | サーバ側で推論する • 背景となる要件 – 推論に大きなコンピュータリソースが必要 – 推論時に、サーバ側にあるデータもあわせて使用する – ネットワークレイテンシーを許容できる • アーキテクチャの自由度が大きい – 推論時にもGPUを利用したい – 他システムとの連携 – クラウドの利用 15
  15. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | マイクロサービス化する • 推論するアプリケーションをマイクロサービス化する – アプリケーションを機能別に異なる小さなサービスに分割し、 APIでCallするような疎結合なシステムにする – マイクロサービス化の利点を享受できる • 変化に強い、柔軟性が高い、継続的なアプリケーション開発 16
  16. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | GraphPipeを使ったアプリケーション:推論 17 学習済みのモデルを装備し、クライアントからの要求に応える … from graphpipe import remote … 画像ファイルを事前処理する img := 画像ファイルを事前処理したもの pred = remote.execute("http://server:port", img) print(np.argmax(pred, axis=1)) $ docker run -it --rm -v "$(pwd)/models:/models/" -p 127.0.0.1:9000:9000 sleepsonthefloor/graphpipe-tf:cpu --model=/models/model.pb --listen=0.0.0.0:9000 入力を渡す 予測結果を返す テンソルデータ テンソルデータ ML Client ML Server GraphPipeライブラリをimportしてCall model= で学習済みのモデルを指定して graphpipeのDockerコンテナを起動する 再掲
  17. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | GraphPipeを使ってマイクロサービス化する 18 画像認識アプリケーションの例 Classy Downloader Preprocessor VGG Client Client 推論する 画像をダウンロードする 画像を事前処理 IN: 画像ファイルまたはURLを受け取る OUT: 推論結果を返す 画像 ファイルの 場合 URLの場合
  18. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | GraphPipe使ってマイクロサービス化 + Oracle Cloudを活用 19 画像認識アプリケーションをOracle Cloud環境で実装する Classy Downloader Preprocessor VGG Client Client 画像ファイルがObject Storageに Uploadされたことをトリガーに 推論を開始する 推論の結果を時刻や撮影場所など 属性と共に記録する Oracle Functions Oracle Events Object Storage 学習や推論をGPUを使って行う Compute Instance
  19. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | デモの内容 21 GraphPipe + Classyコンテナを Oracle Functions (Fn) で Serverless に $ fn list apps NAME ID classy-fn ocid1.fnapp.oc1.phx.XXXXX $ fn list functions classy-fn NAME IMAGE ID classy-func phx.ocir.io/XXXXX/oracle-function/classy-func:0.0.7 ocid1.fnfunc.oc1.phx.XXXXX $ echo -n '{"name": "https://www.oracle.com/assets/candy-177355-ja.jpg"}' |fn invoke classy-fn classy-func {"Id":0,"Message":"result_class=オールドイングリッシュシープドッグ, probability=0.993492"} ✕ Oracle Cloud に 登録した classy-func ファンクション 画像URLを引数に classy-func をCall→ 推論結果が表示される Oracle Functions
  20. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | まとめ • GraphPipeとは – 機械学習の実装面での複雑さからの回避: シンプルなAPI、プロトコル、高速化 – https://oracle.github.io/graphpipe/#/ 22 関連資料はこちらから↓↓
  21. Copyright © 2019, Oracle and/or its affiliates. All rights reserved.

    | Confidential – Oracle Internal/Restricted/Highly Restricted