前言:
眼前大家对“python396教程”大致比较看重,朋友们都想要剖析一些“python396教程”的相关知识。那么小编在网摘上网罗了一些对于“python396教程””的相关文章,希望我们能喜欢,咱们快快来学习一下吧!本文介绍了如何使用Nvidia GPU在Ubuntu 18.04服务器上安装TensorFlow。安装需要具有Nvidia显卡的服务器架构 ,这样的专用服务器可用于各种目的,包括游戏。为了保障设备的使用寿命,建议不要在localhost上安装繁重且耗时的程序。显卡必须支持至少Nvidia compute 3.0才能获得比TensorFlow更多的运用。
我们假设使用64位的操作系统,显卡为GeForce 740m。SSH登录到服务器,更新和升级:
apt update -yapt 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,浏览一下:
nvidia-graphics-drivers-396是最新的,但可能没有太多测试。我们可以添加 nvidia-graphics-drivers-390 PPA 并安装该应用程序。
sudo add-apt-repository ppa:graphics-drivers/ppasudo apt updatesudo apt upgradeubuntu-drivers devicessudo 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工具包:
运行:
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是:
找到已安装CUDA的目录。它正在将文件复制到/usr/local/cuda/。将上述内容移到安装CUDA的目录中并运行这些操作(注意版本编号的目录,以下是格式示例):
tar -xzvf cudnn-9.0-linux-x64-v7.1.tgzsudo cp cuda/include/cudnn.h /usr/local/cuda/includesudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64sudo 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 ~/.bashrcsudo ldconfigecho $CUDA_HOME
安装Bazel:
sudo apt install curlecho "deb [arch=amd64] stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.listcurl | sudo apt-key add -sudo apt update -ysudo apt upgrade -ysudo apt install bazelsudo apt upgrade bazelpip install keras
查看Nvidia版本:
cd ~git clone ~/tensorflow# check current revision number from browsergit checkout r1.11cd ~/tensorflow
通过运行创建配置文件:
./configure
您将得到这样的输出:
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: YDo you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: NDo you wish to build TensorFlow with Hadoop File System support? [Y/n]: NDo you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: NDo you wish to build TensorFlow with Apache Kafka Platform support? [y/N]: NDo you wish to build TensorFlow with XLA JIT support? [y/N]: NDo you wish to build TensorFlow with GDR support? [y/N]: NDo you wish to build TensorFlow with VERBS support? [y/N]: NDo you wish to build TensorFlow with OpenCL SYCL support? [y/N]: NDo you wish to build TensorFlow with CUDA support? [y/N]: YPlease specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 9.0]: 9.0Please specify the location where CUDA 9.1 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cudaPlease specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7.0]: 7.1Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cudaDo you wish to build TensorFlow with TensorRT support? [y/N]: NPlease note that each additional compute capability significantly increases your build time and binary size. [Default is: 5.0] 3.0Do you want to use clang as CUDA compiler? [y/N]: NPlease specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: /usr/bin/gcc-4.8Do you wish to build TensorFlow with MPI support? [y/N]: NPlease specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: -march=nativeWould you like to interactively configure ./WORKSPACE for Android builds? [y/N]:N
构建TensorFlow :
最后的步骤:
bazel-bin/tensorflow/tools/pip_package/build_pip_package tensorflow_pkgcd tensorflow_pkg/sudo pip3 install tensorflow-<name_of_generated_file>.whl
通过切换到另一个目录并运行python来检查您的构建是否正常工作:
import tensorflow as tfhello = tf.constant('Hello World!')sess = tf.Session()print(sess.run(hello))
您将得到Hello World!输出。TensorFlow有以下型号:
您可以运行:
git clone models/tutorials/image/imagenetpython classify_image.py
这是一些基本设置和测试。
标签: #python396教程 #ubuntu更新libcurl #python39如何安装tensorflow #ubuntu安装swig #ubuntu配置tensorflow