深度學習系列之平臺安裝:TensorFlow安裝(gpu版本,ubuntu16.04)

1.安裝驅動:

參考:https://blog.csdn.net/sinat_40276791/article/details/80403784

  • 查看驅動推薦:
    $ ubuntu-drivers devices
    == /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
    modalias : pci:v000010DEd00001C81sv00001028sd000011C0bc03sc00i00
    vendor : NVIDIA Corporation
    model : GP107 [GeForce GTX 1050]
    driver : nvidia-driver-396 - third-party free recommended
    driver : nvidia-driver-390 - third-party free
    driver : xserver-xorg-video-nouveau - distro free builtin

安裝:

$ sudo ubuntu-drivers autoinstall

按照推薦的驅動安裝,如果失敗,請添加NVIDIA driver源倉庫然後在安裝,安裝命令如下:

$ sudo add-apt-repository ppa:graphics-drivers/ppa

在添加源並update之後可通過setting/software update安裝

測試安裝是否成功

$ nvidia-smi

Tue May 22 12:14:56 2018
±----------------------------------------------------------------------------+
| NVIDIA-SMI 390.59 Driver Version: 390.59 |
|-------------------------------±---------------------±---------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|=++==============|
| 0 GeForce GTX 1050 Off | 00000000:01:00.0 Off | N/A |
| 20% 39C P0 N/A / 75W | 444MiB / 2000MiB | 0% Default |
±------------------------------±---------------------±---------------------+

±----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1155 G /usr/lib/xorg/Xorg 28MiB |
| 0 1252 G /usr/bin/gnome-shell 48MiB |
| 0 1539 G /usr/lib/xorg/Xorg 163MiB |
| 0 1713 G /usr/bin/gnome-shell 107MiB |
| 0 2442 G …-token=755D9B9E74B9E412D1116412B89F4DC2 93MiB |
±----------------------------------------------------------------------------+

2.安裝cuda:

  • 下載地址(注意cuda版本和cudnn與tensorflow官網編譯時使用版本一致,見文章末尾鏈接)
    https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=deblocal

  • 下載完成之後通過以下命令安裝

    sudo dpkg -i cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb
    sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
    sudo apt-get update
    sudo apt-get install cuda
  • 如果安裝版本不對,卸載方法如下:

sudo apt-get purge cuda
dpkg -l | grep ^rc | cut -d’ ’ -f3 | sudo xargs dpkg --purge

3.安裝cudnn:

下載地址同上,版本注意與cuda對應

tar -xvf cudnn-9.0-linux-x64-v7.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
  • 添加環境變量:
echo 'export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"' >> ~/.bashrc
echo 'export CUDA_HOME=/usr/local/cuda' >> ~/.bashrc
source ~/.bashrc

4.安裝tensorflow1.14:

pip install tensorflow-gpu==1.14.0
  • check it:

python input:

>>> from tensorflow.python.client import device_lib
>>> device_lib.list_local_devices()

list:
[name: “/device:CPU:0”
device_type: “CPU”
memory_limit: 268435456
locality {
}
incarnation: 8754742150252655686
, name: “/device:GPU:0”
device_type: “GPU”
memory_limit: 1276313600
locality {
bus_id: 1
links {
}
}
incarnation: 17576461877219777618
physical_device_desc: “device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1”
]

官方教程中安裝出錯問題

使用

`pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl`

提示:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/numpy-1.14.3.dist-info'
Consider using the `--user` option or check the permissions.

在最後加上–user即可

  • 按照turorials安裝後example無法執行

tensorflow版本太低,爲0.5.0,需要更新:

pip install --upgrade tensorflow --user

或者在安裝tensorflow時直接指定安裝版本(gpu版本):

pip install pip install tensorflow-gpu==1.8.0

tensorflow安裝後gpu無法啓用,檢查cuda版本和cudnn版本是否與官網編譯環境完全一致:https://www.tensorflow.org/install/source_windows

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章