0. 安裝說明
由於之前安裝caffe 的時候使用的cuda7.0,並不想破壞它,同時又不想使用過低版本的tensorflow,所以才用了Virtualenv installation 方式安裝。
1. 本機配置:
系統:Ubuntu14.04
顯卡:GTX1080
CPU:i7 6500K,其他不重要了
2. 安裝的版本:
tensorflow r0.10
cuda 7.5
cudnn v5.1(我安裝的5.0會出現問題)
3. 參考網址
官網(r0.10,使用Virtualenv installation 安裝):
https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html#requirements
cuda: (需要選對版本)
https://developer.nvidia.com/cuda-downloads
cudnn:(需要註冊)
https://developer.nvidia.com/rdp/cudnn-download
4. 安裝參考網址
http://www.pyimagesearch.com/2016/07/04/how-to-install-cuda-toolkit-and-cudnn-for-deep-learning/
5. 安裝流程
5.1 安裝1080顯卡驅動
1: Download the Nvidia driver in right version (NVIDIA GeForce GTX1080)
2: Edit the blacklist.conf:
sudo gedit /etc/modprobe.d/blacklist.conf
add :
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv
__block_line__
3: sudo apt-get remove –purge nvidia-*
**sudo apt-get remove –purge xserver-xorg-video-nouveau**
4: reboot and into computer using ‘Ctrl+ALT+F1’ using the ‘Ctrl+ALT+F7’ return xservers
5: sudo /etc/init.d/gdm stop or sudo /etc/init.d/lightdm stop
6: in the driver file,which downloaded in step 1
sudo sh NVIDIA.run
7: sudo /etc/init.d/gdm restart or sudo /etc/init.d/lightdm restart
8: sudo reboot
5.2 安裝cuda
1: Download the cuda 7.5 from the cuda_driver
IMPORTANCE:download .runfile
2: reboot and ctrl+alt+F1
sudo /etc/init.d/lightdm stop
3: sudo sh cuda.run
IMPORTANCE:ALL SHOULD INSTALL EXCEPT:DRIVER(because we have installed the nvidia driver and the cuda.runfile don’t include the nvidia driver)
4: sudo /etc/init.d/lightdm restart
5: reboot
5.3 安裝cudnn
tar -zxf cudnn-7.5-linux-x64-v5.1-ga.tgz
cd cuda
sudo cp lib64/* /usr/local/cuda/lib64/
sudo cp include/* /usr/local/cuda/include/
5.4 添加環境變量
gedit .bashrc
export CUDA_HOME=/usr/local/cuda
export PATH="/usr/local/cuda/bin:/usr/local/lib/:${JAVA_HOME}/bin:${PATH}"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64:${LD_LIBRARY_PATH}"
source .bashrc
5.5 Install tensorflow
sudo apt-get install python-pip python-dev python-virtualenv
virtualenv --system-site-packages ~/tensorflow
source ~/tensorflow/bin/activate
# Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
(tensorflow)$ pip install --upgrade $TF_BINARY_URL
6 Important Issue
1 https://github.com/tensorflow/tensorflow/issues/4251
2 如果測試的時候無法導入cudnn,注意LD_LIBRARY_PATH 路徑下是否存在可用的cudnn
3 測試通過需要看看 python -m tensorflow.models.image.mnist.convolutional,不能僅僅看import tensorflow as tf 同時不能用任何問題才能認爲安裝成功
4 更新一個剛剛解決的問題,在安裝tensorflow上經常會出現numpy 版本衝突問題
參考:http://stackoverflow.com/questions/16391335/using-old-version-of-numpy-even-with-a-newer-version-installed
先要找到numpy的存在位置
ipython
import numpy
print numpy.__version__
print numpy.__file__
在我自己的配置下,因爲是Virtualenv installation 方式安裝,所以numpy 會在兩個地方:
/usr/local/lib/python2.7/dist-packages/numpy/__init__.pyc
/home/dex_hand/tensorflow/lib/python2.7/site-packages/numpy/__init__.pyc
所以我通過這樣的方式把兩個地方的numpy 文件夾 都刪除,
rm -rf numpy
最後通過pip install numpy 重新安裝回來,這個時候在tensorflow這個虛擬環境下也能使用到這個版本(1.11.0)的版本的numpy了