ubuntu14.04+nvidia1070+CUDA8.0+CUDNN5.0+opencv2.4.9安装配置
拿到一台全新的电脑,电脑硬件配置为 Intel i7 处理器,16G内存,NVIDIA 1070显卡,显存8G,为了研究深度学习,需要安装配置一系列的工具,当安装好一个全新的Ubuntu 14.04.4 LTS系统后,按照以下步骤,可以完成所有深度学习环境的搭建
首先执行
sudo apt-get update
检查系统自带的源是否可用,如果不可用,那就需要更换源,方法参照链接
http://wiki.ubuntu.org.cn/Qref/Source
JDK1.8
到这里下载需要的JDK
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
解压到指定目录,我指定的是/opt
tar xzvf jdk-[TAB] -C /opt
为了便于书写,可以改一下名字
cd /opt
sudo mv jdk-[TAB] jdk-[your name]
sudo update-alternatives --install /usr/bin/java java /home/chase/jdk1.8.0_111/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /home/chase/jdk1.8.0_111/bin/javac 300
sudo update-alternatives --install /usr/bin/jar jar /home/chase/jdk1.8.0_111/bin/jar 300
sudo update-alternatives --install /usr/bin/javah javah /home/chase/jdk1.8.0_111/bin/javah 300
sudo update-alternatives --install /usr/bin/javap javap /home/chase/jdk1.8.0_111/bin/javap 300
sudo update-alternatives --config java
配置环境变量
这里我直接贴出我的环境变量
sudo gedit .bashrc
export JAVA_HOME=/opt/jdk1.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
配置好环境变量后在用户目录source .bashrc,使环境变量生成
检查是否安装成功。
java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
javac -version
javac 1.8.0_60
ANT1.9.7
a)到Apache官网下载最新版本的ant:http://ant.apache.org/bindownload.cgi
b)解压下载下来的.tar.gz文件到ANTHOME: tar -zxvf apache-ant-1.8.2-bin.tar.gz
c)配置环境变量:
vi ~/.bashrc
export ANT_HOME=ANTHOME
export PATH=$ANT_HOME/bin:$PATH
使环境变量生效:source .bashrc
查看安装版本:ant -version
CUDA8.0
安装NVIDIA 显卡驱动和cuda
首先去官网现在相应的安装包https://developer.nvidia.com/cuda-downloads
禁用nouveau驱动
首先用下面命令查看是否正在使用nouveau
lsmod | grep nouveau
创建文件 /etc/modprobe.d/blacklist-nouveau.conf
blacklist nouveau
options nouveau modeset=0
重新生成 kernel initramfs
sudo update-initramfs -u
安装 .run 文件
重启电脑用 ctrl+alt+F1 进入 tty1, 输入用户名密码登录.
用下列命令关闭lightdm
sudo service lightdm stop
安装run文件: 用默认设置, 并且一路选择accept, yes 即可.
sudo sh cuda__linux.run
安装完成后重启.
配置环境变量
vi ~/.bashrc
export PATH=/usr/local/cuda/bin:$PATH
使环境变量生效:source .bashrc
添加lib库路径:
在 /etc/ld.so.conf.d/ 加入文件cuda.conf内容如下:
/usr/local/cuda/lib64
保存后,执行下列命令使之立刻生效
sudo ldconfig
利用如下命令分别检查NVIDIA驱动是否安装成功和CUDA是否安装成功
nvidia-smi
Sun Dec 4 16:12:38 2016
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.27 Driver Version: 367.27 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1070 Off | 0000:01:00.0 On | N/A |
| 29% 43C P5 8W / 151W | 217MiB / 8109MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1210 G /usr/lib/xorg/Xorg 108MiB |
| 0 2033 G compiz 106MiB |
+-----------------------------------------------------------------------------+
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Wed_May__4_21:01:56_CDT_2016
Cuda compilation tools, release 8.0, V8.0.26
OpenCV
a)下载OpenCV
http://jaist.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip
b)解压
unzip opencv-2.4.9.zip
c)安装Opencv依赖
sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config Python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libv4l-dev
d)编译安装源代码
i.进入源码目录,创建release目录
cd opencv-2.4.9
mkdir release
ii.进入release目录,安装OpenCV的文件都会被放到这个release目录下
cd release
iii.cmake编译OpenCV源码,安装的lib文件都会被安装到/usr/local目录下-D WITH_CUDA=ON 是否编译cuda
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_ARCH_BIN=3.0 -D CUDA_ARCH_PTX=3.0 -D WITH_CUDA=ON -D WITH_V4L=ON ..
iv.安装
sudo make -j8 install
v.检查有没有正确安装
检查/usr/local/share/OpenCV/Java文件夹是否生成
创建软链接
sudo ln -s /usr/local/share/OpenCV/java/libopencv_java249.so /usr/lib/libopencv_java249.so
错误
这里需要指定-D CUDA_ARCH_BIN=6.1 -D CUDA_ARCH_PTX=6.1,可以在https://en.wikipedia.org/wiki/CUDA查询我的1070是6.1
解决方法在此:http://code.opencv.org/issues/3814 下载 NCVPixelOperations.hpp 替换掉替换掉opencv-2.4.9/modules/gpu/src/nvidia/core/NCVPixelOperations.hpp,重新build
GraphCut deprecated in CUDA 7.5 and removed in 8.0
这个错误参考
https://github.com/opencv/opencv/pull/6510/commits/10896129b39655e19e4e7c529153cb5c2191a1db
include "precomp.hpp"
-#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
+// GraphCut has been removed in NPP 8.0
+#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)
void cv::cuda::graphcut(GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
void cv::cuda::graphcut(GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
如果显示gcc版本大于5。3时,修改/usr/local/cuda/include/host_config.h中gcc版本检测即可
#if GNUC > 5 || (GNUC == 5 && GNUC_MINOR > 4)