Ubuntu 18.04 installation Tensorflow (GPU)

First, pull a remote repository

sudo add-apt-repository ppa:jonathonf/python-3.6 

Update Source

sudo apt-get update

Online installation

sudo apt-get install python3.6

Supplement, in fact, with an installed python3: sudo apt-get install python3- dev can be. View Version: python3 --version

Change the default value, python default Python2, now for Python3

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

2.Ubuntu install nvidia graphics driver (a blog on the reference)

View nvidia graphics driver version

nvidia-smi  

3. Install the corresponding version of CUDA

When you install CUDA must pay attention to the NVIDIA graphics driver and the correspondence between Linux systems and versions of GCC, if a mismatch between the version, the installation is unsuccessful.

CUDA Driver and the corresponding version of the 
reference link: https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html 
cuda8.0 and Linux systems as well as correspondence between the GCC 
reference links: HTTPS: // docs.nvidia.com/cuda/archive/8.0/cuda-installation-guide-linux/index.html 
cuda9.0 GCC and Linux systems as well as correspondence between the 
reference link: https://docs.nvidia.com/cuda/archive /9.0/cuda-installation-guide-linux/index.html 
cuda10.0 GCC and Linux systems as well as correspondence between the 
reference link: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index. html

View gcc version:

gcc -v

Since the graphics driver on Ubuntu18.04 RTX2060 is 418.56 version, the selected version of the corresponding mounting cuda10.1

cuda official website to download: https://developer.nvidia.com/cuda-toolkit

Attached historical version: https://developer.nvidia.com/cuda-toolkit-archive

CUDA installation command:
sudo sh cuda_xxx_linux.run

4. Install CUDA version corresponding CUDNN

cudnn官网下载(需要注册):https://developer.nvidia.com/cudnn

另附:https://developer.nvidia.com/rdp/cudnn-archive 

下载Ubuntu18.04对应的CUDNN安装包,然后进入CUDNN安装包所在目录,执行以下命令:

sudo dpkg -i runtime包.deb 
sudo dpkg -i developer包.deb 
sudo dpkg -i 代码sample包.deb

至此,CUDNN安装完成。

5.安装对应版本的Tensorflow

首先要清楚最新版Tensorflow最多支持到CUDA哪个版本?

https://www.tensorflow.org/install/install_sources#common_installation_problems

安装pip3(针对python3): 

sudo apt-get install python3-pip

官方推荐是用Virtualenv安装,不过这里我们仅使用pip进行安装。

sudo pip3 install tensorflow-gpu

 我现在这里安装的是tensorflow_gpu-1.13.1。由于CUDA最新版本是10.1,但是目前最新的tensorflow1.13.1还不支持这个版本,所以只能用CUDA10.0。

推荐搭配:CUDA10.0+CUDNN7.5+tensorflow-gpu1.13.1+python3.6.7

卸载cuda和cudnn,重新安装:

sudo apt remove cudnn*
sudo apt-get remove cuda*
sudo apt-get autoclean
然后在目录切换到/esr/local/下
cd /usr/local/
sudo rm -r cuda-10.1
搞定啦
可以重新安装其他版本啦

设置root用户密码:

sudo passwd root

以下是编辑 profile文件命令:
1.su 然后输入密码 进入root 2.gedit etc/profile 3.编辑保存.

首先确认/etc/profile中的路径包含了cuda10.0的安装路径及相应的库文件
编辑/etc/profile添加:

export PATH=$PATH:/usr/local/cuda-10.0/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/lib64
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda-10.0/lib64

然后
source /etc/profile
使配置文件生效,再次执行。

安装vim:
sudo apt-get install vim
vim --version
问题报错:ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
由于服务器TensorFlow经常报这个错误,
步骤1:
sudo vim ~/.bashrc
按下i进入编辑
在末位加入:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/lib64
export PATH=$PATH:/usr/local/cuda-10.0/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-10.0
按下ESC退出编辑,输入:wq命令进行保存。
使之生效
source ~/.bashrc
步骤2:
据说在修改了步骤1就好了。但是每次我步骤1弄完,问题依旧存在。但是只需要步骤2,问题就可以解决。
检查 /usr/local/cuda-10.0/lib64 下是否有 libcublas.so.10.0
如果有,终端输入:
sudo ldconfig /usr/local/cuda-10.0/lib64

然后终端输入python

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

进行tensorflow是否安装成功的验证。

Guess you like

Origin www.linuxidc.com/Linux/2019-06/158942.htm