TensorFlow
TensorFlowをさわってみたメモ。うちのMacBookはAirなので性能よくないけどひと通りはさわってみれることを期待して、セットアップから実施してみる。
うちのMacにはAnacondaがインストールしてあるので、そこに追加でセットアップ。
Installing TensorFlow on Mac OS X | TensorFlow
手順通りにセットアップできた。Pythonは3.6なので3.6のをインストール。
conda create - tensorflow
source activate tensorflow
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.0-py3-none-any.whl
gocha124noMacBook-Air:~ cha124$ conda create -n tensorflow
Fetching package metadata ...........
Solving package specifications:
Package plan for installation in environment /Users/cha124/anaconda/envs/tensorflow:
Proceed ([y]/n)? y
#
# To activate this environment, use:
# > source activate tensorflow
#
# To deactivate this environment, use:
# > source deactivate tensorflow
#
gocha124noMacBook-Air:~ cha124$ source activate tensorflow
(tensorflow) gocha124noMacBook-Air:~ cha124$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.0-py3-none-any.whl
Collecting tensorflow==1.2.0 from https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.0-py3-none-any.whl
Downloading https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.0-py3-none-any.whl (33.6MB)
100% |████████████████████████████████| 33.6MB 17kB/s
Collecting markdown==2.2.0 (from tensorflow==1.2.0)
Downloading Markdown-2.2.0.tar.gz (236kB)
100% |████████████████████████████████| 245kB 926kB/s
Collecting six>=1.10.0 (from tensorflow==1.2.0)
Downloading six-1.10.0-py2.py3-none-any.whl
Collecting protobuf>=3.2.0 (from tensorflow==1.2.0)
Downloading protobuf-3.3.0.tar.gz (271kB)
100% |████████████████████████████████| 276kB 845kB/s
Collecting bleach==1.5.0 (from tensorflow==1.2.0)
Downloading bleach-1.5.0-py2.py3-none-any.whl
Collecting werkzeug>=0.11.10 (from tensorflow==1.2.0)
Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB)
100% |████████████████████████████████| 317kB 969kB/s
Collecting wheel>=0.26 (from tensorflow==1.2.0)
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
100% |████████████████████████████████| 71kB 1.4MB/s
Collecting html5lib==0.9999999 (from tensorflow==1.2.0)
Downloading html5lib-0.9999999.tar.gz (889kB)
100% |████████████████████████████████| 890kB 538kB/s
Collecting backports.weakref==1.0rc1 (from tensorflow==1.2.0)
Downloading backports.weakref-1.0rc1-py3-none-any.whl
Collecting numpy>=1.11.0 (from tensorflow==1.2.0)
Downloading numpy-1.13.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.5MB)
100% |████████████████████████████████| 4.5MB 120kB/s
Collecting setuptools (from protobuf>=3.2.0->tensorflow==1.2.0)
Downloading setuptools-36.0.1-py2.py3-none-any.whl (476kB)
100% |████████████████████████████████| 481kB 835kB/s
Building wheels for collected packages: markdown, protobuf, html5lib
Running setup.py bdist_wheel for markdown ... done
Stored in directory: /Users/cha124/Library/Caches/pip/wheels/b9/4f/6c/f4c1c5207c1d0eeaaf7005f7f736620c6ded6617c9d9b94096
Running setup.py bdist_wheel for protobuf ... done
Stored in directory: /Users/cha124/Library/Caches/pip/wheels/1b/42/a0/4c7343df5b629ec9c75655468dce7652b28026896b0209ba55
Running setup.py bdist_wheel for html5lib ... done
Stored in directory: /Users/cha124/Library/Caches/pip/wheels/6f/85/6c/56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962
Successfully built markdown protobuf html5lib
Installing collected packages: markdown, six, setuptools, protobuf, html5lib, bleach, werkzeug, wheel, backports.weakref, numpy, tensorflow
Successfully installed backports.weakref-1.0rc1 bleach-1.5.0 html5lib-0.9999999 markdown-2.2.0 numpy-1.13.0 protobuf-3.3.0 setuptools-36.0.1 six-1.10.0 tensorflow-1.2.0 werkzeug-0.12.2 wheel-0.29.0
記述に従って、pythonでハローワールドを実行してみる。
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
(tensorflow) gocha124noMacBook-Air:~ cha124$ python
Python 3.6.0 |Anaconda 4.3.1 (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.costant('Hello, TensorFlow!')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'costant'
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2017-06-26 10:04:15.851049: 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-06-26 10:04:15.851146: 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-06-26 10:04:15.851270: 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-06-26 10:04:15.851324: 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!'
できた。