边肖将与大家分享如何在Ubuntu 18.04服务器上安装TensorFlow。相信大部分人还不太了解,所以分享这篇文章给大家参考。希望你看完这篇文章会有很多收获。我们一起来看看吧!
假设我们使用64位操作系统,显卡是GeForce 740m。SSH登录服务器,更新和升级:
aptupdate-y
apt upgradey运行以下命令安装Python库:
sudoaptinstallopenjdk-8-jdkgitpython-dev python 3-dev python-numpyython 3-numpyython-six python 3-six build-essential python-pippython 3-pippython-virtualenvs Wig python-wheel python 3-wheel libcurl 3-devlibcupti-dev继续运行。
suptinstall libcurl 4-OpenSSL-dev运行,我们可以看到安装的图形硬件:
我们需要安装英伟达驱动程序。我们可以检查SSH上的图形驱动程序:
这是Ubuntu的PPA。看:
https://launchpad.net/~graphics-drivers/档案馆/ubuntu/ppa
Nvidia-graphics-drivers-396是最新的,但可能没有太多测试。我们可以添加nvidia-graphics-drivers-390PPA并安装应用程序。
sud loaded-apt-reportoryppa : graphics-drivers/PPA
sudoaptupdate
sudoaptupgrade
Ubuntu-driver devices
Sudoubuntu-driversautoinstall如果发生意外情况,自动安装不起作用,请运行:
现在,再次运行命令:
Nvidia-smi,你会得到一个有用的输出。我们应该保留这个版本,停止升级。
sudapt-Markholdnvidia-驱动程序-390安装Linux头文件:
suptinstall Linux-headers-$(uname-r)为了让接下来的步骤正常进行,我们需要gcc、g等等:
apinstallgccg gcc-6g-6 gcc-4.8g-4.8
#ifgcc-4.8packagenotfoundrun
# sud loaded-apt-reportoryppa : Ubuntu-tool chain-r/test
# sudoaptupdate
# sudoapinstallgcc-4.8g-4.8现在我们必须安装CUDA工具包:
AdaptNVIDIA-cuda-toolkitlibcupti-dev重启
Sudoreboot安装CUDA工具包:
https://developer.nvidia.com/cuda-toolkit
运行:
cdDownloads/
sudoshcuda _ 9 . 0 . 176 _ 384 . 81 _ Linux . run-override-silent-toolkit接下来,您需要安装CUDNN,NCCL。你需要按照老的PyTorch方法用Nvdia账号登录,非常简单。你会得到链接:CUDNN V7.1.xlib。
rary 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] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list curl https://bazel.build/bazel-release.pub.gpg | 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 https://github.com/tensorflow/tensorflow 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有以下型号:
https://github.com/tensorflow/models
您可以运行:
git clone https://github.com/tensorflow/models.git cd models/tutorials/image/imagenet python classify_image.py
这是一些基本设置和测试。
以上是“怎么在Ubuntu 18.04服务器上安装TensorFlow”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/101263.html