1, first check whether the installation has the following components, if consider completely remove and then install (installation in strict accordance with the following order)
View nvidia version
nvidia-smi
View cuda version
cat /usr/local/cuda/version.txt
View cudnn version
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
2. Install the nvidia driver
1. Disable default graphics driver nouveau
Open the blacklist system, the command is as follows:
south you /etc/modprobe.d/blacklist.conf
Add blacklist.conf file disabled in the display device, the end of the file is added as follows:
# for nvidia display device install
blacklist vga16fb
new blacklist
blacklist rivafb
blacklist rivatv
blacklist nvidiafb
Blacklist.conf save the file, and then update the kernel, the following command:
sudo update-initramfs -u
Restart the computer
sudo reboot
Restart, run the following command (to see if the success is disabled, no output is disabled success):
lsmod | grep again
2. Install the driver RTX1060
First, enter the command line mode
ctrl + alt + f2
Since we want to install the graphics driver, will affect the desktop display, we can turn off the (graphic) 18.04 desktop display manager is gdm3, like here, according to their version of choice
ubuntu 16.04 is lightdm
sudo service lightdm stop
ubuntu 18.04 is gdm3
sudo service gdm3 stop
Add a driving source:
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
Finding the right driver version:
ubuntu-drivers devices
Note here the best Quguan network https://www.geforce.cn/drivers laptop version of the driver to select Notebooks
or
UBUNTU top right corner of the "System Settings" software update "Additional drivers select the" inside look at the system recommended by the version number, it is best to choose based on this, in order to avoid more unknown pit (not recommended to drive directly mounted directly on the additional choice: Failure some high probability, but also cause circulatory problems logged in)
sudo apt-get install nvidia-390
Then open the Desktop Manager or directly reboot
sudo service gdm3 restart
or
sudo reboot
After rebooting
View nvidia version
nvidia-smi
Display the installation was successful
nvidia-settings
Open Set N card
3 Install cuda
First check nvidia driver, cuda, cudnn correspondence between
nvidia cuda with the requirements of the correspondence between the version:
https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
cuda and cudnn need to satisfy the relationship:
https://developer.nvidia.com/rdp/cudnn-archive
3.1 dependent libraries
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-devlibgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
Gcc 3.2 Downgrade
由于Cuda-9.0
只支持gcc-6.0
以下的版本,而Ubuntu18.04系统默认安装的gcc-7.3
版本(可以在终端输入gcc --version
查看系统安装的gcc版本),所以首先需要降级为gcc-5
版本。
- 首先需要安装
gcc-5
在终端输入:
sudo apt install gcc-5
sudo apt install g++-5
- 链接至
gcc-5
版本
在终端输入:
cd /usr/bin
sudo mv gcc gcc.bak #备份
sudo ln -s gcc-5 gcc
sudo mv g++ g++.bak
sudo ln -s g++-5 g++
最后查看系统的gcc版本是否已更改
gcc --version
3.2安装对应版本的Cuda
cuda是nvidia的编程语言平台,想使用GPU就必须要使用cuda
https://developer.nvidia.com/cuda-toolkit-archive
保守起见,选择cuda9.0进行安装,也可以选择更高版本的
注意 9.0 是没有 18.04可选的,但我们选择16.04依然可以安装,正常使用(还没遇到过不正常状态)依次下载下面五个installers
基础安装包
sudo sh cuda_9.0.176.384.81_linux.run --override
在安装过程中 按Q跳过阅读more,会出现几个是否选装和安装位置的选项
其中第二个不需要安装NVIDIA驱动(系统已安装),其余都选择yes或者敲回车。
yes no yes 回车 yes yes 回车
四个更新包
sudo sh cuda_9.0.176.1_linux.run
sudo sh cuda_9.0.176.2_linux.run
sudo sh cuda_9.0.176.3_linux.run
sudo sh cuda_9.0.176.4_linux.run
修改环境变量
安装完Cuda-9.0
后,还需要将其添加至系统环境变量。
ubuntu下某些程序需要自己定义LD_LIBRARY_PATH,修改下面文件的环境变量:
sudo gedit ~/.bashrc
打开“profile”文件,在末尾处添加(注意不要有空格,不然会报错):
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64$:LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
#注意这里不要写cuda几点几,因为我们要实现多版本切换
或者你不需要切换版本
export PATH="$PATH:/usr/local/cuda-9.0/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64"
保存文本后,更新系统环境变量:
source ~/.bashrc
至此,可以通过在终端输入nvcc -V
,检查Cuda-9.0
是否安装成功。
也可以测试cuda的Samples
cd /usr/local/cuda-9.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
运行最后显示Result = Pass
注意路径要根据你自己的进行修改
如果显示的是一些关于GPU的信息,则说明安装成功了。
4.安装对应版本的cudnn
首先去官网下载你需要的cudnn,下载的时候需要注册账号。选择对应你cuda版本的cudnn下载。
https://developer.nvidia.com/rdp/cudnn-archive
安装完Cuda之后,继续安装与Cuda-9.0
版本对应的Cudnn
cuDNN v7.3.1 Library for Linux
下载时候保存为:cudnn-9.0-linux-x64-v7.4.1.5.tgz
下载后安装非常简单,就是解压然后拷贝到相应的系统CUDA路径下,注意最后一行拷贝时 "-d"不能少,
tar -zxvf cudnn-9.0-linux-x64-v7.4.1.5.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*
没有报错就是全部安装完成了
完成后,可以到~/NVIDIA_CUDA-9.0_Samples/文件夹下测试CUDA功能完整性
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
5.安装opencv-python版本
安装pip3,执行命令
sudo apt install python3-pip
安装libopencv-dev依赖包
sudo apt install libopencv-dev
安装opencv-python库
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python
安装成功
python3 import cv2 print(cv2.__version__)
6.安装opencv 3.2.0
6.1.安装opencv依赖包
- GCC 4.4.x or later
- CMake 2.6 or higher
- Git
- GTK+2.x or higher, including headers (libgtk2.0-dev) # 控制opencv GUI
- pkg-config
- Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
- ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
- [optional] libtbb2 libtbb-dev
- [optional] libdc1394 2.x
- [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev # 处理图像所需的包
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包
sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能 sudo apt-get install ffmpeg
sudo apt-get install libgstreamer-plugins-base1.0-dev
依赖包libjasper-dev
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
6.2.下载opencv-3.4.4
安装opencv可以直接使用命令安装,这里我们下载opencv源码进行编译安装,如下图,官网链接 Releases - OpenCV library:
选择 3.4.4 Sources
wget https://github.com/opencv/opencv/archive/3.4.4.zip
这里建议用linux平台可用的motrix (类似迅雷) 下载
6.3 解压下载好的opencv-3.4.4.zip 然后安装opencv
cd opencv-3.4.4/
mkdir build
cd build
在cmake配置过程中,需要下载ippicv_2019_lnx_intel64_general_20180723.tgz文件,这个文件下载速度超级慢
总是会卡在(因为墙的缘故,下载龟速,基本都是失败)
-- IPPICV: Download: ippicv_2019_lnx_intel64_general_20180723.tgz
所以这里选择离线单独从百度网盘下载这个文件
百度网盘链接: https://pan.baidu.com/s/1f6QGwcbMNbL9vDLwUX1w6A 提取码: i47f
假设 ippicv_2019_lnx_intel64_general_20180723.tgz 下载后
放置于
/home/joe/Downloads
找到并修改ippicv.make文件
/home/joe/Downloads/opencv-3.4.4/3rdparty/ippicv/ippicv.cmake
修改前:
41 set(THE_ROOT "${OpenCV_BINARY_DIR}/3rdparty/ippicv")
42 ocv_download(FILENAME ${OPENCV_ICV_NAME}
43 HASH ${OPENCV_ICV_HASH}
44 URL
45 "${OPENCV_IPPICV_URL}"
46 "$ENV{OPENCV_IPPICV_URL}"
47 "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/"
48 DESTINATION_DIR "${THE_ROOT}"
49 ID IPPICV
50 STATUS res 51 UNPACK RELATIVE_URL)
修改后
41 set(THE_ROOT "${OpenCV_BINARY_DIR}/3rdparty/ippicv")
42 ocv_download(FILENAME ${OPENCV_ICV_NAME}
43 HASH ${OPENCV_ICV_HASH}
44 URL
45 "${OPENCV_IPPICV_URL}"
46 "$ENV{OPENCV_IPPICV_URL}"
47 "file:///home/joe/Downloads/"
48 DESTINATION_DIR "${THE_ROOT}"
49 ID IPPICV
50 STATUS res 51 UNPACK RELATIVE_URL)
修改后,下载 ippicv
文件时,会自动从本地文件加载.
更详细的步骤可以参照原文
https://www.aiuai.cn/aifarm792.html
做好预先准备后紧接着前面
cd build
配置命令如下:(这里没有搞定启用opencv cuda加速)
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
使用如下命令进行编译:
make -j7
执行安装命令如下:
sudo make install
安装完成提示如下图:
测试opencv安装是否成功,执行命令如下:
opencv_version
# 3.4.4
6.4.添加路径
这类似于Windows中装完Java要在环境变量里添加PATH一样,为了让系统能够识别,需要做以下几步: 在终端中输入如下语句,打开这个文件:
sudo vim /etc/ld.so.conf.d/opencv.conf
在最后一行添加一句话”/usr/local/lib
“,当然它也可能是空的,没关系。输入vim可能会提示你找不到命令,你只需要apt-get install vim
,安装一下包再输入命令就可以了。或者如果你不会vim命令,那就直接按照路径/etc/ld.so.conf.d/
去找,在该目录下新建一个opencv.conf
文件,并且打开编辑,将”/usr/local/lib
“添加进去,保存退出即可。
然后运行以下代码配置库:
sudo ldconfig
注意输入完后,什么都不会出现,只是类似于库配置完后刷新一下。然后再打开另一个文件:/etc/bash.bashrc
。你可以选择用命令行sudo gedit /etc/bash.bashrc
打开或者直接打开都可以。在文件末尾添加两行:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存并关闭。至此,OpenCV的库就编译和安装完了。撒花~
opencv虽然安装了,但是opecv基于cuda问题没有解决,这里也向小伙伴求助,欢迎小伙伴来指导。
如果opencv安装有以下问题configuring incomplete, errors occurred! 可以参考下面的博客
经过谷歌解决了这个问题
参考csdn中这个大佬的博客 原因解析:cuda9不再支持2.0架构
解决方案如下:
1).找到FindCUDA.cmake文件
找到行
find_cuda_helper_libs(nppi)
改为
find_cuda_helper_libs(nppial) find_cuda_helper_libs(nppicc) find_cuda_helper_libs(nppicom) find_cuda_helper_libs(nppidei) find_cuda_helper_libs(nppif) find_cuda_helper_libs(nppig) find_cuda_helper_libs(nppim) find_cuda_helper_libs(nppist) find_cuda_helper_libs(nppisu) find_cuda_helper_libs(nppitc)
2).找到行
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")
改为
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")
3).找到行
unset(CUDA_nppi_LIBRARY CACHE)
改为
unset(CUDA_nppial_LIBRARY CACHE) unset(CUDA_nppicc_LIBRARY CACHE) unset(CUDA_nppicom_LIBRARY CACHE) unset(CUDA_nppidei_LIBRARY CACHE) unset(CUDA_nppif_LIBRARY CACHE) unset(CUDA_nppig_LIBRARY CACHE) unset(CUDA_nppim_LIBRARY CACHE) unset(CUDA_nppist_LIBRARY CACHE) unset(CUDA_nppisu_LIBRARY CACHE) unset(CUDA_nppitc_LIBRARY CACHE)
4).找到文件OpenCVDetectCUDA.cmake
修改以下几行
...
set(__cuda_arch_ptx "")
if(CUDA_GENERATION STREQUAL "Fermi")
set(__cuda_arch_bin "2.0")
elseif(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0 3.5 3.7") ...
改为
...
set(__cuda_arch_ptx "")
if(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0 3.5 3.7")
elseif(CUDA_GENERATION STREQUAL "Maxwell")
set(__cuda_arch_bin "5.0 5.2") ...
5).cuda9中有一个单独的halffloat(cuda_fp16.h)头文件,也应该被包括在opencv的目录里
将头文件cuda_fp16.h添加至 opencv\modules\cudev\include\opencv2\cudev\common.hpp
即在common.hpp中添加
#include <cuda_fp16.h>
6)重新cmake
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
问题解决
7.卸载Cuda和Cudnn
卸载Cuda-9.0
终端输入
cd /usr/local/cuda-9.0/bin
sudo ./uninstall_cuda_9.0.pl
卸载Cudnn
终端输入
sudo apt remove cudnn*
8.安装tensorflow-gpu
直接通过pip安装Tensorflow-gpu
sudo pip3 install tensorflow-gpu
9. 安装teamviewer
官网选择linux版本,下载ubuntu版本deb安装包,官网链接地址:下载 Linux 版 TeamViewer,进行远程桌面访问和协作
wget https://download.teamviewer.com/download/linux/teamviewer_amd64.deb
这里建议用linux平台可用的motrix (类似迅雷) 下载
下载完成,使用如下命令进行deb包的安装:
sudo dpkg -i teamviewer_amd64.deb
如果出现依赖库安装失败执行如下命令,强制更新类库依赖:
sudo apt-get install -f
安装完成,执行启动teamviewer命令如下:
teamviewer
本文终
本文参考整理自
https://blog.csdn.net/hancoder/article/details/86634415
https://zhuanlan.zhihu.com/p/57803337?utm_source=wechat_session&utm_medium=social&s_r=0
https://www.aiuai.cn/aifarm792.html