[tenserflow] Macにインストール編

2016/12/01

AI Python テクノロジー

t f B! P L
今年は、ビジネス系の雑誌でも、エンジニア系のセミナーでも、会社内でも、社外でも、「AI」「機械学習」「ディープラーニング」という単語を見ない(聞かない)日がないぐらいの流行っぷりの人工知能だが、 Google製のOSS「tensorflow」をようやく使ってみようと、非常に重い腰を上げてみた。

関連サイト

ダウンロード

https://www.tensorflow.org/versions/r0.12/get_started/os_setup.html

インストール

https://www.tensorflow.org/versions/r0.12/get_started/os_setup.html#virtualenv-installation

hello world

http://senyoltw.hatenablog.jp/entry/2016/05/07/231041

下準備

$ python -V Python 2.7.9 $ sudo easy_install pip $ sudo pip install --upgrade virtualenv $ virtualenv --system-site-packages ./ drwxr-xr-x 7 user staff 238B 11 29 11:49 . drwxr-xr-x 25 user staff 850B 11 29 11:46 .. lrwxr-xr-x 1 user staff 78B 11 29 11:49 .Python -> /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/Python drwxr-xr-x 16 user staff 544B 11 29 11:49 bin drwxr-xr-x 3 user staff 102B 11 29 11:49 include drwxr-xr-x 3 user staff 102B 11 29 11:49 lib -rw-r--r-- 1 user staff 60B 11 29 11:49 pip-selfcheck.json

インストール

# アクティベート(TensorFlow環境) $ source bin/activate (tenserflow) $ pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py2-none-any.whl 膨大なエラー発生 You are using pip version 6.0.8, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. You are using pip version 6.0.8, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting tensorflow==0.12.0rc0 from https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0rc0-py2-none-any.whl Exception: Traceback (most recent call last): File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/basecommand.py", line 232, in main status = self.run(options, args) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/commands/install.py", line 339, in run requirement_set.prepare_files(finder) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_set.py", line 355, in prepare_files do_download, session=self.session, File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/download.py", line 782, in unpack_url session, File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/download.py", line 667, in unpack_http_url from_path, content_type = _download_http_url(link, session, temp_dir) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/download.py", line 814, in _download_http_url stream=True, File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/_vendor/requests/sessions.py", line 473, in get return self.request('GET', url, **kwargs) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/download.py", line 365, in request return super(PipSession, self).request(method, url, *args, **kwargs) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/_vendor/requests/sessions.py", line 461, in request resp = self.send(prep, **send_kwargs) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/_vendor/requests/sessions.py", line 573, in send r = adapter.send(request, **kwargs) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/_vendor/cachecontrol/adapter.py", line 43, in send resp = super(CacheControlAdapter, self).send(request, **kw) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/_vendor/requests/adapters.py", line 431, in send raise SSLError(e, request=request) SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581) どうやらpipのバージョンが古いことが原因だったらしい $ pip -V pip 6.0.8 from /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg (python 2.7) pipのアップグレード $ sudo easy_install --upgrade pip $ pip -V pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7) インストール # Mac OS X, CPU only, Python 2.7: (tensorflow)$ pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0rc0-py2-none-any.whl (tensorflow)$ pip install --upgrade $TF_BINARY_URL Collecting tensorflow==0.12.0rc0 from https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0rc0-py2-none-any.whl Downloading https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0rc0-py2-none-any.whl (38.5MB) 100% |████████████████████████████████| 38.5MB 18kB/s Collecting numpy>=1.11.0 (from tensorflow==0.12.0rc0) Downloading numpy-1.11.2-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.9MB) 100% |████████████████████████████████| 3.9MB 183kB/s Collecting mock>=2.0.0 (from tensorflow==0.12.0rc0) Downloading mock-2.0.0-py2.py3-none-any.whl (56kB) 100% |████████████████████████████████| 61kB 2.5MB/s Requirement already up-to-date: six>=1.10.0 in /usr/local/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from tensorflow==0.12.0rc0) Collecting protobuf==3.1.0 (from tensorflow==0.12.0rc0) Downloading protobuf-3.1.0-py2.py3-none-any.whl (339kB) 100% |████████████████████████████████| 348kB 934kB/s Requirement already up-to-date: wheel in ./lib/python2.7/site-packages (from tensorflow==0.12.0rc0) Collecting funcsigs>=1; python_version < "3.3" (from mock>=2.0.0->tensorflow==0.12.0rc0) Downloading funcsigs-1.0.2-py2.py3-none-any.whl Collecting pbr>=0.11 (from mock>=2.0.0->tensorflow==0.12.0rc0) Downloading pbr-1.10.0-py2.py3-none-any.whl (96kB) 100% |████████████████████████████████| 102kB 2.4MB/s Collecting setuptools (from protobuf==3.1.0->tensorflow==0.12.0rc0) Using cached setuptools-29.0.1-py2.py3-none-any.whl Installing collected packages: numpy, funcsigs, pbr, mock, setuptools, protobuf, tensorflow Found existing installation: setuptools 12.0.5 Not uninstalling setuptools at /usr/local/lib/python2.7/site-packages/setuptools-12.0.5-py2.7.egg, outside environment /Users/yugeta/MAMP/tenserflow/bin/.. Successfully installed funcsigs-1.0.2 mock-2.0.0 numpy-1.11.2 pbr-1.10.0 protobuf-3.1.0 setuptools-29.0.1 tensorflow-0.12.0rc0 問題なくインストール完了 ちなみに、GPUバージョンは以下のコマンド # Mac OS X, GPU enabled, Python 2.7: (tensorflow)$ pip install --upgrade https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.0rc0-py2-none-any.whl アクティベート終了 $ deactivate

そしておもむろにHelloWorld!

$ vi hello.py -- import tensorflow as tf hello = tf.constant('Hello World !!') sess = tf.Session() print sess.run(hello) ファイルを保存して、実行 $ python hello.py Hello World !! 実行速度が微妙に遅く感じるのは気のせいか? そもそも、スピードを競う製品ではないからかもしれないので、あまり突っ込むのはヨシコさん。

まだまだ人工知能の入り口に過ぎない・・・

この後の工程は、データをぶち込んで行く作業だ・・・ 実はそんな簡単ではなく、Pythonをゴリゴリに書いていかなくてはいけないようだ・・・ 別の言語でもいいんだが、Pythonが楽しそうなので、この道を選択!! 乞うご期待!

人気の投稿

このブログを検索

ごあいさつ

このWebサイトは、独自思考で我が道を行くユゲタの少し尖った思考のTechブログです。 毎日興味がどんどん切り替わるので、テーマはマルチになっています。 もしかしたらアイデアに困っている人の助けになるかもしれません。

ブログ アーカイブ