CPU 版 TensorFlow を Azure 仮想マシンに構築する

47
CPU 版 TensorFlow を Azure 仮想マシンに構築する Japan Windows Azure User Group Microsoft MVP for Microsoft Azure 冨田 (とみたすなお) http://twitter.com/harutama

Transcript of CPU 版 TensorFlow を Azure 仮想マシンに構築する

Page 1: CPU 版 TensorFlow を Azure 仮想マシンに構築する

CPU 版 TensorFlow をAzure 仮想マシンに構築する

Japan Windows Azure User Group

Microsoft MVP for Microsoft Azure

冨田 順 (とみたすなお)

http://twitter.com/harutama

Page 2: CPU 版 TensorFlow を Azure 仮想マシンに構築する

大前提

2

Page 3: CPU 版 TensorFlow を Azure 仮想マシンに構築する

以下のものが必要です

• パソコン– Android タブレットとか iPad でもできないことはないかも

• SSH するための何か– Linux・MacOS ならコマンドで

– Windows なら PuTTY とか TeraTerm とかBash on Windows という手段もアリ

• Microsoft アカウント–これは絶対に必要です。

https://account.microsoft.com/

3

Page 4: CPU 版 TensorFlow を Azure 仮想マシンに構築する

注意

• 必要がなくなった仮想マシンは、停止・削除を自身の責任で実施してください。

–インスタンスを削除・停止することを忘れたことに伴って発生する課金については、自身の責任となります。

• 仮想マシンの停止・削除については本スライドの最後に記述しています。

4

Page 5: CPU 版 TensorFlow を Azure 仮想マシンに構築する

リソースグループの作成

リソースグループは、様々なリソース(仮想マシンとかネットワークインターフェースとか)を入れるための箱だと思ってください。

5

Page 6: CPU 版 TensorFlow を Azure 仮想マシンに構築する

リソースグループを選択

6

Page 7: CPU 版 TensorFlow を Azure 仮想マシンに構築する

新規に作成します

7

Page 8: CPU 版 TensorFlow を Azure 仮想マシンに構築する

リソースグループの作成

8

• リソースグループ名各自で好きな名前をつけてください。

• サブスクリプション利用料金が課金されるサブスクリプションを指定します。

• リソースグループの場所「米国東部」を指定します。

Page 9: CPU 版 TensorFlow を Azure 仮想マシンに構築する

できました

9

Page 10: CPU 版 TensorFlow を Azure 仮想マシンに構築する

仮想マシンの作成

10

Page 11: CPU 版 TensorFlow を Azure 仮想マシンに構築する

作成したリソースグループに仮想マシンを追加します

11

Page 12: CPU 版 TensorFlow を Azure 仮想マシンに構築する

「ubuntu」と入力して…

12

Page 13: CPU 版 TensorFlow を Azure 仮想マシンに構築する

「Ubuntu Server 16.04 LTS」を選択します。

13

Page 14: CPU 版 TensorFlow を Azure 仮想マシンに構築する

「作成」

14

Page 15: CPU 版 TensorFlow を Azure 仮想マシンに構築する

基本設定の構成

15

• 名前各自で好きな名前をつけてください。

• VMディスクの種類「HDD」に変更します

• ユーザー名SSHでログインする際のユーザー名を、各自で好きな名前を指定してください。

• パスワードSSHでログインする際のパスワードです。

• サブスクリプション利用料金が課金されるサブスクリプションを指定します。

• リソースグループの場所「米国東部」を指定します。

Page 16: CPU 版 TensorFlow を Azure 仮想マシンに構築する

「すべて表示」させて

16

Page 17: CPU 版 TensorFlow を Azure 仮想マシンに構築する

「DS14_V2」を選択

17

Page 18: CPU 版 TensorFlow を Azure 仮想マシンに構築する

「オプション機能の設定」はそのまま「OK」

18

Page 19: CPU 版 TensorFlow を Azure 仮想マシンに構築する

最終確認画面で「OK」

19

Page 20: CPU 版 TensorFlow を Azure 仮想マシンに構築する

20

仮想マシンができあがるまで

しばし待ちましょう

Page 21: CPU 版 TensorFlow を Azure 仮想マシンに構築する

「Virtual Machines」から

21

Page 22: CPU 版 TensorFlow を Azure 仮想マシンに構築する

作成した仮想マシンを選択

22

Page 23: CPU 版 TensorFlow を Azure 仮想マシンに構築する

ここにIPが表示されます

23

Page 24: CPU 版 TensorFlow を Azure 仮想マシンに構築する

24

割り当てられた IP に対してSSH でログインしてみてください

$ ssh ユーザー名@IPアドレス

Page 25: CPU 版 TensorFlow を Azure 仮想マシンに構築する

ポートの開放

デフォルトでは SSH のための 22 番ポートしか開いていません。

追加で必要となるポートを開放します。

25

Page 26: CPU 版 TensorFlow を Azure 仮想マシンに構築する

「Virtual Machines」から作成した仮想マシンを選択

26

Page 27: CPU 版 TensorFlow を Azure 仮想マシンに構築する

仮想マシンが使っているネットワークインターフェースを選択

27

Page 28: CPU 版 TensorFlow を Azure 仮想マシンに構築する

ネットワークインターフェースが使うセキュリティグループを選択

28

Page 29: CPU 版 TensorFlow を Azure 仮想マシンに構築する

セキュリティグループの受信規則に開放するポートを追加

29

ここから2つの規則を追加します(ポート 6006 と 80)

Page 30: CPU 版 TensorFlow を Azure 仮想マシンに構築する

6006番ポートの開放

30

• 名前各自で好きな名前をつけてください。

• 優先度「1010」

• ソース「Any」のまま

• サービス「カスタム」

• プロトコル「TCP」

• ポート範囲「6006」

• アクション「許可」

Page 31: CPU 版 TensorFlow を Azure 仮想マシンに構築する

80番ポートの開放

31

• 名前各自で好きな名前をつけてください。

• 優先度「1020」

• ソース「Any」のまま

• サービス「HTTP」

• アクション「許可」

Page 32: CPU 版 TensorFlow を Azure 仮想マシンに構築する

規則が追加されました

32

Page 33: CPU 版 TensorFlow を Azure 仮想マシンに構築する

TensorFlow のインストールhttp://qiita.com/rindai87/items/6ce68114b21e0a446f09

33

Page 34: CPU 版 TensorFlow を Azure 仮想マシンに構築する

SSH で接続します

34

Page 35: CPU 版 TensorFlow を Azure 仮想マシンに構築する

モジュールのインストール

35

# パッケージリストの更新sudo apt-get -y update

# インストール済みのパッケージの更新sudo apt-get -y upgrade

# Python関連で必要となるもモジュールのインストールsudo apt-get -y install python-pip python-dev python-scipy git

Page 36: CPU 版 TensorFlow を Azure 仮想マシンに構築する

TensorFlow のインストール

36

# TensorFlowのダウンロードURLの設定export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.0rc1-cp27-none-linux_x86_64.whl

# pipを利用したTensorFlowのインストールsudo pip install --upgrade $TF_BINARY_URL

# TensorFlowのソースコードの取得(サンプルを動かして動作確認を行うため)cd ~git clone https://github.com/tensorflow/tensorflow.git

# デモアプリの動作に必要となるPythonライブラリのインストールsudo pip install tornado futures Pillow

Page 37: CPU 版 TensorFlow を Azure 仮想マシンに構築する

TensorFlow の動作確認

37

cd ~/tensorflow

# mnist(softmax版)の動作確認python tensorflow/examples/tutorials/mnist/mnist_softmax.py

# mnist(DNN版)の動作確認python tensorflow/examples/tutorials/mnist/fully_connected_feed.py

特にエラーが発生せずに終了すればTensorFlow が正しくインストールされています。

Page 38: CPU 版 TensorFlow を Azure 仮想マシンに構築する

仮想マシンの停止

38

Page 39: CPU 版 TensorFlow を Azure 仮想マシンに構築する

仮想マシンの停止

39

Page 40: CPU 版 TensorFlow を Azure 仮想マシンに構築する

この状態で課金が停止されます

40

Page 41: CPU 版 TensorFlow を Azure 仮想マシンに構築する

停止させる際の注意

• OSをシャットダウンさせた状態では仮想マシンの課金は停止されません。

– OSシャットダウンでは各種のリソースが占有された状態が継続するため、課金も継続します。

41

OS をシャットダウンした状態でポータルから仮想マシンを見ると

このような表示になる

「停止」ボタンをクリックするとリソースが開放されて課金も停止する

Page 42: CPU 版 TensorFlow を Azure 仮想マシンに構築する

仮想マシンの削除

42

Page 43: CPU 版 TensorFlow を Azure 仮想マシンに構築する

仮想マシンの削除

• 仮想マシンだけを削除しても、他のリソースは残ってしまいます。

–ストレージ・ネットワークインターフェース・パブリックIP etc…

• リソースグループを削除すれば、仮想マシンとその周辺リソースを一括削除できます。

–取り消しできない操作なので、削除の際は慎重に作業しましょう。

43

Page 44: CPU 版 TensorFlow を Azure 仮想マシンに構築する

リソースグループを選択

44

Page 45: CPU 版 TensorFlow を Azure 仮想マシンに構築する

リソースグループを削除

45

Page 46: CPU 版 TensorFlow を Azure 仮想マシンに構築する

ちゃんと確認して削除

46

Page 47: CPU 版 TensorFlow を Azure 仮想マシンに構築する

Let’s dream and then let’s build.- Ray Ozzie

冨田 順 (@harutama)http://twitter.com/harutama

47