読者です 読者をやめる 読者になる 読者になる

Mac OS X でTensorflowインストール、Hello world

基本の流れ

$ 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を使ってインストール(追記アリ)
    • 画面左隅のりんごまーく > About this macGPUを確認して、TF_PYTHON_URLを設定
      • 僕のMacIntel Iris Graphics 6100GPUなので対応範囲外。
$ 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
$ 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!'

改善

>>> 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' って何。。。