Mac OS X でTensorflowインストール、Hello world
- https://www.tensorflow.org/install/install_mac を参考に、Anacondaベースでインストールする
基本の流れ
先立って、Anacondaをインストールしておく
“tensorflow"という名称でconda環境を作る
$ conda create -n tensorflow Fetching package metadata ........... Solving package specifications: Package plan for installation in environment /Users/kz/anaconda/envs/tensorflow: Proceed ([y]/n)? y # # To activate this environment, use: # > source activate tensorflow # # To deactivate this environment, use: # > source deactivate tensorflow #
- condaの"tensorflow"環境をアクティベート
$ source activate tensorflow (tensorflow) $
- pipを使ってインストール(追記アリ)
$ TF_PYTHON_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py3-none-any.whl (tensorflow) ~$ echo $TF_PYTHON_URL https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py3-none-any.whl (tensorflow) ~$ pip install --ignore-installed --upgrade $TF_PYTHON_URL (omit) Installing collected packages: six, numpy, pyparsing, packaging, appdirs, setuptools, protobuf, werkzeug, wheel, tensorflow Successfully installed appdirs-1.4.3 numpy-1.12.1 packaging-16.8 protobuf-3.3.0 pyparsing-2.2.0 setuptools-35.0.2 six-1.10.0 tensorflow-1.1.0 werkzeug-0.12.1 wheel-0.29.0
追記:
- この後 jupyter で ModuleNotFoundError: No module named 'tensorflow' エラー - kz-engineer -SCRAP- でハマる
- マニュアルどおりでなく
pip install tensorflow
するべき
Hello world で validation してみる
$ python Python 3.6.0 |Anaconda custom (x86_64)| (default, Dec 23 2016, 13:19:00) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() 2017-05-13 14:25:30.045839: 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-13 14:25:30.045866: 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-13 14:25:30.045872: 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. 2017-05-13 14:25:30.045877: W 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-05-13 14:25:30.045882: W 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. >>> print(sess.run(hello)) b'Hello, TensorFlow!'
改善
- 警告が気になる
- ソースからコンパイルするともっと早くなるという警告なので、無視していい
- ログメッセージレベルを調整して出ないようにする
- 参考: https://github.com/tensorflow/tensorflow/issues/7778
>>> import os >>> os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
- OK!
>>> import os >>> import tensorflow as tf >>> os.environ['TF_CPP_MIN_LOG_LEVEL']='2' >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) b'Hello, TensorFlow!'
疑問点
b'Hello, TensorFlow!'
のb'
って何。。。