ついにというかやっというか、、tensorflowを動かしてみることにした*1。自宅PCはWindows10で、VMware Playerを入れてその中でUbuntuを走らせています。tensorflowは素で入れず仮想化環境等の専用環境(isolated pythonとか?)で入れるべしということらしいので、dockerを入れてその中でtensorflowを動かすことにした。だから、何階層にもなっているので性能は問わず、勉強するのが第一目的。。GPUを使わないと全然性能が出ないらしいし。。
UbuntuにDockerを入れる。自分は以下のように入れてしまった。docker.ioが本体らしい。dockerパッケージとは何者??
sudo apt-get install docker sudo apt-get install docker.io
tensorflowのコンテナをインストールガイドに従って以下のコマンドで走らせてみる
sudo docker run -it gcr.io/tensorflow/tensorflow bash
普通なら素でパッケージを一つずつ入れるところですが、Googleサイトには、(汚染しない?・汚染されないため?)仮想環境で動かせと明記されているので、だったらもうdockerで一発で入れてしまえと。。dockerは楽だ。。ちなみに、、この方法で入れるとPythonは2.7
root@901853fd062d:/notebooks# python Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>>
tensorflowがimportできたので準備は整った。今日はもう寝る。。
tensorflowを理解するために買った本
TensorFlowで学ぶディープラーニング入門 ~畳み込みニューラルネットワーク徹底解説~
- 作者: 中井悦司
- 出版社/メーカー: マイナビ出版
- 発売日: 2016/09/27
- メディア: 単行本(ソフトカバー)
- この商品を含むブログ (1件) を見る
■追記(170527)
docker内で準備されているパッケージを確認、Pythonは2.7と3.5が入れられていた。
root@a2396092270d:/notebooks# dpkg --list *略* ii python 2.7.11-1 amd64 interactive high-level object-oriented language (defaul ii python-apt-common 1.1.0~beta1build1 all Python interface to libapt-pkg (locales) ii python-dev 2.7.11-1 amd64 header files and a static library for Python (default) ii python-minimal 2.7.11-1 amd64 minimal subset of the Python language (default version) ii python2.7 2.7.12-1ubuntu0~1 amd64 Interactive high-level object-oriented language (versio ii python2.7-dev 2.7.12-1ubuntu0~1 amd64 Header files and a static library for Python (v2.7) ii python2.7-minimal 2.7.12-1ubuntu0~1 amd64 Minimal subset of the Python language (version 2.7) ii python3 3.5.1-3 amd64 interactive high-level object-oriented language (defaul ii python3-apt 1.1.0~beta1build1 amd64 Python 3 interface to libapt-pkg ii python3-dbus 1.2.0-3 amd64 simple interprocess messaging system (Python 3 interfac ii python3-gi 3.20.0-0ubuntu1 amd64 Python 3 bindings for gobject-introspection libraries ii python3-minimal 3.5.1-3 amd64 minimal subset of the Python language (default python3 ii python3-pycurl 7.43.0-1ubuntu1 amd64 Python bindings to libcurl (Python 3) ii python3-software-properti 0.96.20.5 all manage the repositories that you install software from ii python3.5 3.5.2-2ubuntu0~16 amd64 Interactive high-level object-oriented language (versio ii python3.5-minimal 3.5.2-2ubuntu0~16 amd64 Minimal subset of the Python language (version 3.5)
コンテナは起動した状態ではbashプロセスのみが稼働
root@a2396092270d:/notebooks# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.3 18240 3224 ? Ss 23:30 0:00 bash root 17 0.0 0.2 34424 2864 ? R+ 23:36 0:00 ps aux
動作確認のためのミニマムプログラムを実行、、なんかちょっと怒られる
https://www.tensorflow.org/install/install_linux#ValidateYourInstallation
root@a2396092270d:/notebooks# python Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>> hello = tf.constant('Hello') >>> sess = tf.Session() 2017-05-26 23:41:47.826684: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 2017-05-26 23:41:47.826786: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-05-26 23:41:47.826805: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. >>> sess.run(hello) 'Hello' >>>
このエラーについて、ぐぐると、、CPUの拡張命令を使うかどうかによるエラーらしく、多分、高速化できる拡張命令である?SSE4.1 , SSE4.2,AVXを使いたかったけど、これらを使えるようにはコンパイルされていません(拡張命令使えないので遅いよ)。というメッセージなんだろうと解釈
https://ja.wikipedia.org/wiki/Streaming_SIMD_Extensions (Wiki; SSE4.1 , SSE4.2 , AVX等の拡張命令についての説明)
■追記
Dockerコンテナはrunで起動するとイメージからコンテナが生成される(初期状態からの開始)
コンテナ内で何か変更作業を終えてコンテナを停止するとsnapshotとして履歴が一時的に保持される。
次回runで起動すると上記snapshotからコンテナは起動されず、オリジナルのイメージからコンテナが生成される。
すると、修正を加えたのに消えた!!となる。これを回避するには、2回目の実行はrunではなくstartを用いる。
startの際、先にrunで起動、編集後stopで止めたコンテナの識別子を指定することで、変更内容が反映された状態で
コンテナが立ち上がる。snapshotが取られているコンテナ一覧は、docker ps -a で一覧表示させることが可能。
snapshotからのstartを行わず毎回runを続けるとdocker環境はsnapshotで一杯になる。
■追記(160527)
最初はコンテナに入ってプログラミングしようと思っていたけどviも何も入っていないので、ipythonでつかってみることにする。ipython(jupyter)で起動するには以下(tensorflowのガイドより)
sudo docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow
ubuntuでlocalhost:8888で接続できたけど認証パスワードを聞かれる。あぁーめんどくさいーー。。ローカルでしか使わないのにーー。よく見ると起動時に認証用tokenがコンソールに出ていました。すみません。
左がDocker内でipythonで起動した後、Ubuntu内のブラウザからlocalhost:8888で接続したところ。tutorialのNoteが3種類用意されている。まぁ至れり尽くせりではあります。
後から分かったのだが、Ubuntuに入らなくてもUbuntuのeth0ポートに8888で接続してもアクセス可能であった。ListenIPの条件がANYになっているから?いずれにせよ、Ubuntuに入らずともホストOS(Windows10)から直接操作できるのはかなり助かる。例えば、Ubuntuのeth0が192.168.233.135で、起動時のTokenが5eed5....の場合、以下のURLにアクセスすることでホストOS(Windows10とか)からiPythonの画面に接続可能
http://192.168.233.135:8888/?token=5eed5e3aXXXXXXXXXXXXXXXXXXXXXXXXX93
■追記(160604)
上記方法で起動すると、2回目のStartでログイントークン(認証用パスワード)が表示されず、また、初回のrunの時のパスワードは再利用されないので、入れなくなる。だから、、起動時は以下のように明示する必要あり。さらに、、できれば/notebookのディレクトリはdocker内ではなく、ホスト側のDISKにマウントするのが望ましいので、以下のような起動が良いと思われる。(結局ガイド本の通り())
mkdir -p ~/docker/tensor01 sudo docker run -it -p 8888:8888 -v ~/docker/tensor01:/notebooks -e PASSWORD=1234 --name tensor01 gcr.io/tensorflow/tensorflow
- ログイン用パスワードは環境変数で指定 (1234と安易に設定)
- DISKはホスト側のDISKにマウント ( /notebooks -> ~/docker/tensor01)
ただし、、上記方法で構築すると、オリジナルのコンテナで用意されていた/notebook領域が見えなくなるので、サンプルとか空っぽの状態で立ち上がる。
■ご参考URL
Tensorflowインストールガイド
https://www.tensorflow.org/install/install_linux
Getting Started With TensorFlow(本家による最初の一歩)
https://www.tensorflow.org/get_started/get_started
ありがたいことに日本語訳↓ (de0ta様)
http://qiita.com/de0ta/items/05b2b87437c8386aa2e0
*1:仕事の自主テーマ(自習テーマ?)で学習ネタをやるかもしれず。。