需要のないページ

プログラミングや趣味や。

Condaを使ってTensorFlowの野良ビルドを導入する

前書き

前回の記事の続きっちゃ続き。環境は、Windows10の64bit機だ。

ただし、この記事ではCPU版のインストールだけ実践する。

 

TensorFlowは、深層学習によく用いられるフレームワークである。

公式サイトは、次のように説明している。

TensorFlow™ is an open source software library for numerical computation using data flow graphs.

使いづらいと揶揄されるが、あくまで本質は計算ライブラリのようだ。

 

TensorFlowのインストール (公式による)

公式サイトが簡潔なインフォメーションを出している。

適当にまとめてみる。(稚拙な和訳/強引な意訳)

  • CPUのみをサポートするものと、GPUも利用するものとの二種類がある
  • GPUが利用できる環境は次の通り
    • CUDA Toolkit 8.0が入っていて、パスが通っている
    • 上記CUDAに対応するNVIDIAドライバが搭載されている
    • cuDNN v5.1が入っていて、パスが通っている
    • GPUのCompute Capabilityが3.0以上である
  • GPUが利用できる場合も、まずはCPU版を試してみることを勧める

 

  • インストールの際は、次の二通りの方法がある
    • "native" pipを利用するもの (推奨)
      • pip3 install --upgrade tensorflow
      • pip3 install --upgrade tensorflow-gpu
    • Anacondaを利用するもの (公式のサポート外)
      • pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.1.0-cp35-cp35m-win_amd64.whl
      • pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-win_amd64.whl

 

このインフォは親切だが、condaを用いたインストールは出来ないのだろうか?

 

TensorFlowのインストール (condaを用いる)

予め確認しておくが、この方法は公式に保証されたものではない。

こだわりなくインストールしたいのなら、native pipを用いるのが確実だ。

 

野良ビルドリポジトリは、Anaconda Cloudで検索できる*1

適合する条件をちょいちょい入力すると、次の結果が表示された。

f:id:LouiS:20170606164033p:plain

投稿現在(2017/06)、4件のリポジトリが表示される。リンクはこちら

 

この中で最もダウンロード数の多い、一番上の候補を選んだ。

緑色のリンクをクリックすると、インストールコマンドが表示される。

conda install -c conda-forge tensorflow=1.1.0

こいつをAnacondaプロンプトに叩き込んでやればよい。

 

以下、実際のプロンプト画面。

前もって、Python3.5の仮想環境をactivateしていることに注意されたい。

f:id:LouiS:20170606165401p:plain

 

PyCharmで試してみる

公式インフォQiitaの投稿を参考に、次のテストコードを実行してみた。

 

ほぼほぼパクリだが、先頭二行のコードで警告レベルを変更した。

当初この二行を除いて実行した結果、怒涛のWarningに襲われたからである。

C:\Users\[UserName]\AppData\Local\conda\conda\envs\python35\python.exe C:/Users/[UserName]/temp/py35test/test.py
2017-06-06 17:18:42.845745: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2017-06-06 17:18:42.863110: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-06 17:18:42.863465: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-06 17:18:42.863802: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\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-06-06 17:18:42.864145: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\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-06-06 17:18:42.864488: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\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.
2017-06-06 17:18:42.864843: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-06 17:18:42.865197: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
b'Hello, TensorFlow!'
32
Process finished with exit code 0

適切に実行されているようであるが、警告がなんにせようざったい。

 

適宜検索検討して、これらの警告をにぎりつぶすことに決めた。

  1. これらの警告は、CPUの拡張命令をフルに活かせていないことを指摘するもので、自前でビルドしなおすことで解消される。

  2.  ビルドしなおすと確かに速くなるが、その効果は限定的で、それだったらGPUを使える環境を整える方が圧倒的に理にかなっている。

  3. 頑張ってCPUの実行速度を最適化しても、GPUの実行速度には影響しない。(GPUの方が圧倒的に貢献度が高い状況だと、CPUに合わせてチューニングしても意味が薄い)

 

警告レベルを変えれば、(当たり前だが)表面上はすっきり実行される。

C:\Users\[UserName]\AppData\Local\conda\conda\envs\python35\python.exe C:/Users/[UserName]/temp/py35test/test.py
b'Hello, TensorFlow!'
32

Process finished with exit code 0

 

せっかくなので

せっかくなのでKerasも叩き込んだ。

conda install -c conda-forge keras=2.0.2

f:id:LouiS:20170607162451p:plain

まだ試していないが。

 

後書き

上記の例では、TensowFlowの機能の1%も使えていないだろう。

GitHubからTensorFlowを活用したリポジトリを落として、解析しなければ。

なお、ボトムアップ的(?)な学習には、以下の公式ページが参考になりそうだ。

あと、GPU試す。これ大事。

*1:サインインしなくても普通に使える

/* コードブロック */