重装好几回了!没有人比我更懂重装(不是
如今我默认你们都才装好ubuntu18.04,就是干!请注意!我这里是经过安装cuda来安装显卡驱动!想要单独安装显卡驱动(好比英伟达官网下载run文件或者经过ubuntu-drivers devices来安装系统推荐的驱动版本)的同窗请看其余教程!可是(◔◡◔)重装屡次的我以为,反正都要装cuda,因此经过cuda安装nvidia是最简单不过啦~
注:sudo是获取临时root权限,因此咱们开局直接进root
如今咱们来看下大体流程:
cuda(顺便安装显卡驱动)–> cudnn --> anaconda3 -->搭建环境–>安装tensorflow-gpu
python
-
换源(加快下载速度
使用root权限:
sudo -s
备份源码:
cp /etc/apt/sources.list /etc/apt/sources.list.bak
替换源列表内容:
gedit /etc/apt/sources.list
打开list后,将如下内容替换掉原来的:
linux# 默认注释了源码镜像以提升 apt update 速度,若有须要可自行取消注释 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse # 预发布软件源,不建议启用 # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
记得点保存
更新列表:
apt-get update
OK,换源成功!
ubuntu -
禁用系统自带的显卡驱动
打开系统禁用列表:
gedit /etc/modprobe.d/blacklist.conf
经过添加如下代码,将nouveau拉入黑名单!哼,咱们不和它玩儿!:
blacklist nouveau
options nouveau modset=0
而后更新下咱们修改的内容,让它生效:
update-initramfs -u
重启:
reboot
再看看这玩意儿还敢出来不:
lsmod | grep nouveau
OK,没有任何输出(它怕了 它怕了哈哈
bash -
安装相关依赖
安装gcc(记得进入root模式哦:
apt install build-essential
ionic -
安装cuda(安装它对应的显卡驱动
宝贝们乖乖去官网下载哦~
—>指路http://developer.nvidia.com/cuda-downloads
到安装文件目录下运行.run文件(萌新小妙招~输入cd再空一格,将存放run文件的文件夹拖入终端,再回车,就能够进入安装目录啦~而后输入ls还能够查看目录下的文件哦):
sh cuda_10.0.130_410.48_linux.run
舒适提示:记得替换为本身的cuda文件名
安装过程当中,输入accept
若是以前没有装显卡驱动,那么在安装cuda的过程当中能够在这里安装哦(是我本人了
测试Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48? (y)es/(n)o/(q)uit: y
不要选择openGL!ui
Do you want to install the OpenGL libraries? (y)es/(n)o/(q)uit [ default is yes ]: n
关于这个服务(可y可n:url
Do you want to run nvidia-xconfig? This will update the system X configuration file so that the NVIDIA X driver is used. The pre-existing X configuration file will be backed up. This option should not be used on systems that require a custom X configuration, such as systems with multiple GPU vendors. (y)es/(n)o/(q)uit [ default is no ]: n
后面的问题都y或者enter默认,来看看结果:spa
=========== = Summary = =========== Driver: Installed Toolkit: Installed in /usr/local/cuda-10.0 Samples: Installed in /home/yy, but missing recommended libraries
安装完成后,须要添加环境变量:
gedit ~/.bashrc
在文件最后加入如下代码(记得改为本身的cuda版本哦
命令行export PATH="/usr/local/cuda-10.0/bin:$PATH" export LD_LIBRARY_PATH="/usr/lcoal/cuda-10.0/lib64:$LD_LIBRARY_PATH"
添加并保存,将文件生效:
source ~/.bashrc
最后咱们查看下cuda的版本信息以及nvidia驱动信息:
nvcc -V
cuda的版本信息以下:nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA Corporation Built on Sat_Aug_25_21:08:01_CDT_2018 Cuda compilation tools, release 10.0, V10.0.130
nvidia驱动信息查询:
nvidia-smi
查询结果以下:Wed Aug 12 15:59:46 2020 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 410.48 Driver Version: 410.48 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 Graphics Device Off | 00000000:01:00.0 Off | N/A | | N/A 41C P0 N/A / N/A | 0MiB / 3020MiB | 1% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+
-
安装cudnn
去官网下载压缩包
—>指路https://developer.nvidia.com/rdp/cudnn-archive
下载好后,咱们来解压它(此时压缩包在你的下载目录下:
首先进入下载目录,而后开始解压:
tar -zxvf cudnn-10.0-linux-x64-v7.4.2.24.tgz
解压结果以下:cuda/include/cudnn.h cuda/NVIDIA_SLA_cuDNN_Support.txt cuda/lib64/libcudnn.so cuda/lib64/libcudnn.so.7 cuda/lib64/libcudnn.so.7.4.2 cuda/lib64/libcudnn_static.a
而后咱们须要把cudnn移动到cuda中:
cp -P cuda/lib64/libcudnn* /usr/local/cuda-10.0/lib64/
cp cuda/include/cudnn.h /usr/local/cuda-10.0/include/
为全部用户设置读取权限(记得改为你本身的版本号!
chmod a+r /usr/local/cuda-10.0/include/cudnn.h
chmod a+r /usr/local/cuda-10.0/lib64/libcudnn*
查看cudnn版本信息:
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
结果以下(个人是7.4.2:#define CUDNN_MAJOR 7 #define CUDNN_MINOR 4 #define CUDNN_PATCHLEVEL 2 -- #define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
-
安装anaconda3
没有下载的宝贝,去清华源(速度贼快
请看路—>https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/
进入下载文件的目录中运行:
bash Anaconda3-2020.02-Linux-x86_64.sh
为anaconda加入环境变量:
gedit ~/.bashrc
在bashrc的最后加入(记得修改成本身的用户名:export PATH="/home/yy/anaconda3/bin:$PATH"
最后别忘更新下:
source ~/.bashrc
-
搭建环境
确保本身在root模式下!建立环境(tf是我本身命名的,你们根据本身喜爱改~:
conda create -n tf python=3.7
激活刚刚咱们建立的环境:
source activate tf
激活后,咱们的命令行开头就有环境名啦~说明此时咱们正处于tf这个环境中:root@yy:~# source activate tf (tf) root@yy:~#
-
安装tensorflow-gpu
在激活环境中输入(直接用pip太慢了,因此我后面加上了清华源连接:
pip install tensorflow-gpu==1.13.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
网很差的时候可能就会全红,就会像下面同样报错read timed out,不要紧多安几回,总有网顺的时候:File "/home/yy/anaconda3/envs/tf/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 576, in stream data = self.read(amt=amt, decode_content=decode_content) File "/home/yy/anaconda3/envs/tf/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 541, in read raise IncompleteRead(self._fp_bytes_read, self.length_remaining) File "/home/yy/anaconda3/envs/tf/lib/python3.7/contextlib.py", line 130, in __exit__ self.gen.throw(type, value, traceback) File "/home/yy/anaconda3/envs/tf/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 442, in _error_catcher raise ReadTimeoutError(self._pool, None, "Read timed out.") pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Read timed out.
安装完毕后,进入
python
再输入import tensorflow as tf
测试下:(tf) root@yy:~# python Python 3.7.7 (default, May 7 2020, 21:25:33) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf Traceback (most recent call last): File "/home/yy/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "/home/yy/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "/home/yy/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "/home/yy/anaconda3/envs/tf/lib/python3.7/imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "/home/yy/anaconda3/envs/tf/lib/python3.7/imp.py", line 342, in load_dynamic return _load(spec) ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
哇噢,报错了耶,不要捉鸡!先输入quit()退出python,
再在命令行输入:
ldconfig /usr/local/cuda-10.0/lib64
结果以下:>>> quit() (tf) root@yy:~# ldconfig /usr/local/cuda-10.0/lib64 (tf) root@yy:~# python Python 3.7.7 (default, May 7 2020, 21:25:33) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>>
呼~报错解除!此时咱们查看下numpy的版本:
>>> import numpy >>> numpy.__version__ '1.19.1'
好像版本过高啦,咱们下降下版本:
pip install -U numpy==1.16.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
到这里就所有结束啦~
我跑下pointnet++康康
**作个小测试,只跑一个epoch
parser.add_argument('--num_point', type=int, default=1024, help='Point Number [default: 1024]') parser.add_argument('--max_epoch', type=int, default=1, help='Epoch to run [default: 251]') parser.add_argument('--batch_size', type=int, default=8, help='Batch Size during training [default: 16]')
very good!彻底莫得问题!
(tf) root@yy:/media/yy/Data/ipython_jupyter/pointnet2123# python train.py **** EPOCH 000 **** 2020-08-12 17:13:44.277590 ---- batch: 050 ---- mean loss: 3.805058 accuracy: 0.127500 ---- batch: 100 ---- mean loss: 3.299858 accuracy: 0.205000 .......这里太多了,省略掉......... ---- batch: 1200 ---- mean loss: 1.797384 accuracy: 0.492500 2020-08-12 17:18:01.698818 ---- EPOCH 000 EVALUATION ---- eval mean loss: 1.345066 eval accuracy: 0.606969 eval avg class acc: 0.502087 Model saved in file: log/model.ckpt