갈루아의 반서재

Photo by Jeswin Thomas from Pexels

이제 Tensorflow 설치시에는 더 이상 pip 를 사용하지 않는 편이 좋겠다. pip가 아닌 conda를 사용하여 Tensorflow 를 설치해야하는 데에는는 크게 2가지 이유가 있다. 아래에서 살펴보자.

Chart taken from https://www.anaconda.com/blog/developer-blog/tensorflow-in-anaconda/

먼저 첫 번째 장점은 더욱 향상된 CPU 성능이다. 위에서 보다시피 conda 설치시 pip 설치와 비교하여 speed boost 가 최대 8배 차이가 나는 것을 볼 수 있다. 이 부분은 주로 CPU 를 사용중인 머신 러닝 학습자에게 크게 도움이 되는 부분이라 할 수 있겠다. MKL 라이브러리가 텐서플로우 패키지 속도를 향상시켜주는 것 이외에도, NumPy, NumpyExr, SciPy, 그리고 Scikit-Learn 등 다른 주요 라이브러리의 속도 향상에도 효과가 있다. 

다음으로 GPU 버전 설치 과정이 더욱 간단해졌다는 점이다. conda 설치의 경우 GPU 지원에 필요한 CUDA 와 CuDNN 라이브러리를 자동으로 설치해준다. 반면 pip 설치의 경우 이 과정을 수동으로 진행해야 한다. 

먼저 기존에 pip로 설치한 tensorflow 를 제거한다. 아래에서 보다시피 현재 2.1 버전이 설치되어 있다.

(quantum) founder@hilbert:~$ pip list
Package                Version
---------------------- -------------------
tensorflow             2.1.0

다음과 같이 삭제를 진행한다.

pip uninstall tensorflow

이제 conda 를 이용하여 tensorflow 를 설치한다.

conda install tensorflow

단, 파이썬 버전이 3.8의 경우 다음과 같은 설치가 되지 않으니, 이 경우 3.7 등 하위 버전으로 다운그레이드한 후 설치해야 한다.

(quantum) founder@hilbert:~$ conda list python$
# packages in environment at /home/founder/anaconda3/envs/quantum:
#
# Name                    Version                   Build  Channel
ipython                   7.13.0           py38h32f6830_2    conda-forge
python                    3.8.2                hcf32534_0
(quantum) founder@hilbert:~$ conda install tensorflow
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: |
Found conflicts! Looking for incompatible packages. failed

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - tensorflow -> python[version='2.7.*|3.6.*|3.7.*|3.5.*']

Your python: python=3.8

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

그리고 GPU 버전을 사용하고자 한다면, 다음과 같이 tensorflow 를 tensorflow-gpu 로 바꿔서 실행하면 된다. 

conda install tensorflow-gpu

더 자세한 내용은 아래 링크를 참조하세요.

https://www.anaconda.com/tensorflow-in-anaconda/

 

TensorFlow in Anaconda - Anaconda

  TensorFlow is a Python library for high-performance numerical calculations that allows users to create sophisticated deep learning and machine learning applications. Released as open source software in 2015, TensorFlow has seen tremendous growth and…

www.anaconda.com