2016년 1월 24일 일요일

osx - tensorflow 설치

https://gist.github.com/haje01/202ac276bace4b25dd3f

글을 참조했으나 권한 문제로 OS X에선 몇가지 문제를 해결해야한다.
먼저

sudo easy_install pip
sudo pip install --upgrade virtualenv

virtualenv 를 설치하자.

virtualenv --system-site-packages ~/tensorflow
cd ~/tensorflow

tensorflow 를 위한 환경을 만들어주고

source bin/activate

활성화 하자.
그 다음부터 진행.

pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
아래와 같이 되면 성공이다.

(tensorflow) ➜  tensorflow  pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
Collecting tensorflow==0.5.0 from https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
  Using cached https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
Requirement already up-to-date: six>=1.10.0 in /Library/Python/2.7/site-packages (from tensorflow==0.5.0)
Collecting numpy>=1.9.2 (from tensorflow==0.5.0)
  Downloading numpy-1.10.4-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.7MB)
    100% |████████████████████████████████| 3.7MB 96kB/s 
Installing collected packages: numpy, tensorflow
  Found existing installation: numpy 1.10.1
    Not uninstalling numpy at /Library/Python/2.7/site-packages, outside environment /Users/spectrum/tensorflow
  Found existing installation: tensorflow 0.5.0
    Not uninstalling tensorflow at /Library/Python/2.7/site-packages, outside environment /Users/spectrum/tensorflow
Successfully installed numpy-1.10.4 tensorflow-0.5.0

생각해보니 openCV 할때도 이렇게 할껄 그랬네.

python 열고

>>> import tensorflow as tf

오류 없이 잘 된다.

예제대로 진행해보았다.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
can't determine number of CPU cores: assuming 4
I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 4
can't determine number of CPU cores: assuming 4
I tensorflow/core/common_runtime/local_session.cc:45] Local session inter op parallelism threads: 4
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>> 

오호? CPU Core 갯수를 모르겠으나 4개로 짐작한다라는 경고가 뜬다.

>>> NUM_CORES = 4
>>> sess = tf.Session()

이렇게 코어 갯수를 지정할 수 있다.

아직 iOS지원이라던가 병렬처리쪽이 공개가 안되었는데 눈팅하고 있어야겠다.