如何在Ubuntu 18.04伺服器上安裝TensorFlow(Nvidia GPU)
本文介紹瞭如何使用Nvidia GPU在Ubuntu 18.04伺服器上安裝TensorFlow。安裝需要具有Nvidia顯示卡的伺服器架構 ,這樣的專用伺服器可用於各種目的,包括遊戲。為了保障裝置的使用壽命,建議不要在localhost上安裝繁重且耗時的程式。顯示卡必須支援至少Nvidia compute 3.0才能獲得比TensorFlow更多的運用。
我們假設使用64位的作業系統,顯示卡為GeForce 740m。SSH登入到伺服器,更新和升級:
apt update -y apt upgrade –y
執行這個命令來安裝Python庫:
sudo apt install openjdk-8-jdk git python-dev python3-dev python-numpy python3-numpy python-six python3-six build-essential python-pip python3-pip python-virtualenv swig python-wheel python3-wheel libcurl3-dev libcupti-dev
繼續執行
sudo apt install libcurl4-openssl-dev
透過執行,我們可以看到安裝的顯示卡硬體:
sudo lshw -C display | grep product
我們需要安裝Nvidia驅動程式。我們可以檢查SSH上的圖形驅動程式:
nvidia-smi
這是Ubuntu的PPA,瀏覽一下:
~graphics-drivers/+archive/ubuntu/ppa
nvidia-graphics-drivers-396是最新的,但可能沒有太多測試。我們可以新增 nvidia-graphics-drivers-390 PPA 並安裝該應用程式。
sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt update sudo apt upgrade ubuntu-drivers devices sudo ubuntu-drivers autoinstall
如果有意外情況,autoinstall不起作用,則執行:
sudo apt install nvidia-390
現在,再次執行命令:
nvidia-smi
您將得到一個有用的輸出。我們應該保持住這個版本停止升級。
sudo apt-mark hold nvidia-driver-390
安裝 Linux—headers :
sudo apt install linux-headers-$(uname -r)
為了後續步驟正常進行,我們需要 gcc, g++ 等等:
apt install gcc g++ gcc-6 g++-6 gcc-4.8 g++-4.8 # if gcc-4.8 package not found run # sudo add-apt-repository ppa:ubuntu-toolchain-r/test # sudo apt update # sudo apt install gcc-4.8 g++-4.8
現在我們必須安裝CUDA工具包:
apt install nvidia-cuda-toolkit libcupti-dev
重啟
sudo reboot
安裝CUDA工具包:
https://developer.nvidia.com/cuda-toolkit
執行:
cd Downloads/ sudo sh cuda_9.0.176_384.81_linux.run --override --silent –toolkit
接下來,您需要安裝CUDNN,NCCL。您需要按照PyTorch老方法,使用Nvdia帳戶登入,這很簡單。您將獲得連結:cuDNN v7.1.x Library for Linux。您需要下載deb檔案,並將FTP上傳到伺服器。URL是:
https://developer.nvidia.com/rdp/cudnn-download
https://developer.nvidia.com/nccl
找到已安裝CUDA的目錄。它正在將檔案複製到/usr/local/cuda/。將上述內容移到安裝CUDA的目錄中並執行這些操作(注意版本編號的目錄,以下是格式示例):
tar -xzvf cudnn-9.0-linux-x64-v7.1.tgz sudo cp cuda/include/cudnn.h /usr/local/cuda/include sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
以上將節省空間,並避免apt警告。開啟配置檔案,如.bashrc:
nano ~/.bashrc
新增這些:
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64" export CUDA_HOME=/usr/local/cuda
重新載入:
source ~/.bashrc sudo ldconfig echo $CUDA_HOME
安裝Bazel:
sudo apt install curl echo "deb [arch=amd64] | sudo tee /etc/apt/sources.list.d/bazel.list curl | sudo apt-key add - sudo apt update -y sudo apt upgrade -y sudo apt install bazel sudo apt upgrade bazel pip install keras
檢視Nvidia版本:
cd ~ git clone cd ~/tensorflow # check current revision number from browser git checkout r1.11 cd ~/tensorflow
透過執行建立配置檔案:
./configure
您將得到這樣的輸出:
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3 Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: Y Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: N Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: N Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: N Do you wish to build TensorFlow with Apache Kafka Platform support? [y/N]: N Do you wish to build TensorFlow with XLA JIT support? [y/N]: N Do you wish to build TensorFlow with GDR support? [y/N]: N Do you wish to build TensorFlow with VERBS support? [y/N]: N Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: N Do you wish to build TensorFlow with CUDA support? [y/N]: Y Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 9.0]: 9.0 Please specify the location where CUDA 9.1 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7.0]: 7.1 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda Do you wish to build TensorFlow with TensorRT support? [y/N]: N Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 5.0] 3.0 Do you want to use clang as CUDA compiler? [y/N]: N Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: /usr/bin/gcc-4.8 Do you wish to build TensorFlow with MPI support? [y/N]: N Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: -march=native Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]:N
構建TensorFlow :
最後的步驟:
bazel-bin/tensorflow/tools/pip_package/build_pip_package tensorflow_pkg cd tensorflow_pkg/ sudo pip3 install tensorflow-<name_of_generated_file>.whl
透過切換到另一個目錄並執行python來檢查您的構建是否正常工作:
import tensorflow as tf hello = tf.constant('Hello World!') sess = tf.Session() print(sess.run(hello))
您將得到Hello World!輸出。TensorFlow有以下型號:
您可以執行:
git clone cd models/tutorials/image/imagenet python classify_image.py
這是一些基本設定和測試。
來自 “ News360 ”,原文連結:http://blog.itpub.net/31545819/viewspace-2215255/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 在Ubuntu 18.04安裝tensorflow 1.12 GPU版本UbuntuGPU
- 在Ubuntu 18.04上安裝TensorflowUbuntu
- ubuntu16+tensorflow-gpu安裝cudaUbuntuGPU
- Ubuntu 16.04 安裝 Tensorflow Gpu版本UbuntuGPU
- Ubuntu18.04安裝/解除安裝NVIDIA顯示卡驅動Ubuntu
- 如何在 Ubuntu 上安裝 EMQX MQTT 伺服器UbuntuMQQT伺服器
- ubuntu18.04 上安裝jdkUbuntuJDK
- 教你如何在 Ubuntu 18.04 中安裝 gThumb 3.9.1Ubuntu
- vultr教程:如何在ubuntu18.04上安裝Hestia控制皮膚Ubuntu
- 如何在 Ubuntu 上安裝 MongoDBUbuntuMongoDB
- 如何在 Ubuntu 上安裝 OctoberCMSUbuntu
- ubuntu18.04安裝dns伺服器UbuntuDNS伺服器
- tensorflow-gpu 安裝GPU
- 如何在 Ubuntu 18.04 上更新韌體Ubuntu
- 如何在 Ubuntu 伺服器上安裝桌面環境 (GUI)Ubuntu伺服器GUI
- ubuntu 18.04 安裝dockerUbuntuDocker
- Ubuntu18.04上安裝NS-3Ubuntu
- 如何在 Ubuntu 上安裝 VirtualBoxUbuntu
- docker安裝tensorflow-gpuDockerGPU
- Tensorflow GPU版本安裝教程GPU
- Ubuntu 安裝 tensorflow-gpu 1.4 +CUDA 8.0 +cuDNN詳細教程UbuntuGPUDNN
- 滴滴雲GPU雲伺服器Ubuntu系統安裝Ubuntu桌面GPU伺服器Ubuntu
- Ubuntu 18.04 LTS安裝numbaUbuntu
- 在Ubuntu 20.04中安裝Nvidia V100 GPU驅動UbuntuGPU
- 如何在 Ubuntu 上安裝 Python 3.8UbuntuPython
- 如何在 Ubuntu 上安裝 FireFox 15UbuntuFirefox
- 如何在Ubuntu24.04上安裝ELKUbuntu
- Ubuntu安裝nvidia-dockerUbuntuDocker
- Windows安裝tensorflow教程 GPU版WindowsGPU
- 在 Ubuntu18.04 上安裝 Docker CE (社群版)UbuntuDocker
- Ubuntu18.04上安裝ROS的詳細教程UbuntuROS
- Ubuntu 18.04 安裝配置 MySQL 5.7UbuntuMySql
- Ubuntu18.04安裝NginxUbuntuNginx
- Ubuntu18.04安裝GhostUbuntu
- ubuntu18.04安裝dockerceUbuntuDocker
- ubuntu18.04 安裝dockerUbuntuDocker
- 通過第三方倉庫PPA在Ubuntu18.04上安裝NVIDIA顯示卡驅動Ubuntu
- Ubuntu 14 Caffe安裝(無GPU)UbuntuGPU