本文基于深度學習基礎平臺環境,搭建深度學習基礎平臺請參考深度學習:Ubuntu16.04+雙TitanX+CUDA8.0+CUDNN5.1。官方提供了多種安裝方式,這里推薦使用PIP安裝方式,簡單快速,如果PIP官方源太慢,可更改為國內鏡像源,參考解決Python pip官方源安裝緩慢、出錯:
要求
Requirements
The TensorFlow Python API supports Python 2.7 and Python 3.3+.
The GPU version works best with Cuda Toolkit 8.0 and cuDNN v5.1. Other versions are supported (Cuda toolkit >= 7.0 and cuDNN >= v3) only when installing from sources.
安裝
sudo apt-get install python-pip python-dev
For installing the version with GPU support, please use:
sudo pip install tensorflow-gpu
測試
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> sess.run(a+b)
42
>>>
是不是很簡單,更過安裝方式請參考Tensorflow官方之南