텐서플로를 Mac 및 다양한 환경에서 설치하는 방법은 텐서플로 홈페이지(https://www.tensorflow.org/install/)를 참고 하면 된다.
여기서는 virtualenv를 이용하여 텐서플로를 설치 해보록 하자
일반적으로 파이썬으로 작업을 할 때는 vitualenv라는 가상환경을 사용해야 합니다. virtualenv는 한 컴퓨터에서 여러 프로젝트를 작업할 때 파이썬 패키지의 의존성이 출동하지 않도록 관리해주는 툴입니다. 즉 virtualenv를 사용하여 텐서플로를 설치하면 의존성 때문에 같이 설치되는 패키지들이 다른 프로젝트에서 설치한 같은 패키지들을 덮어쓰지 않게 됩니다.
텐서플로 홈페이지에서도 virtualenv 를 설치하도록 권장하고 있다.
We recommend the virtualenv installation. Virtualenv is a virtual Python environment isolated from other Python development, incapable of interfering with or being affected by other Python programs on the same machine. During the virtualenv installation process, you will install not only TensorFlow but also all the packages that TensorFlow requires. (This is actually pretty easy.) To start working with TensorFlow, you simply need to "activate" the virtual environment. All in all, virtualenv provides a safe and reliable mechanism for installing and running TensorFlow.
Native pip installs TensorFlow directly on your system without going through any container or virtual environment system. Since a native pip installation is not walled-off, the pip installation might interfere with or be influenced by other Python-based installations on your system. Furthermore, you might need to disable System Integrity Protection (SIP) in order to install through native pip. However, if you understand SIP, pip, and your Python environment, a native pip installation is relatively easy to perform.
Install with virtualenv
1. pip 및 virtualenv 설치
$ sudo easy_install pip $ pip install --upgrade virtualenv
2. tensorflow 디렉토리에 가상환경 생성 및 활성화
$ virtualenv --system-site-packages -p python3 tensorflow $ source ~/tensorflow/bin/activate
3. 텐서플로 및 패키지들 설치
(tensorflow)$ easy_install -U pip (tensorflow)$ pip3 install --upgrade tensorflow
4. 비활성화
(tensorflow)$ deactivate
5. 텐서플로 삭제
rm -r ~/tensorflow
6. 텐서플로 동작 확인 예제 (test.py)
import tensorflow as tf a = tf.placeholder("float") b = tf.placeholder("float") y = tf.multiply(a, b) sess = tf.Session() print (sess.run(y, feed_dict={a:3, b:3}))
7. 결과 확인
(tensorflow)$ python3 test.py 2018-01-08 22:36:41.154298: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA 9.0
'ⓘⓣ > 인공지능' 카테고리의 다른 글
[컨벌루션 신경망] Convolutional neural network (커브넷) (0) | 2018.01.08 |
---|---|
[AI] 텐서플로 (TensorFlow) (0) | 2017.12.16 |