ubuntu kylin 14.06+cuda8+cudnn5+opencv3.1+caffe环境搭建

1,安装显卡驱动

我的显卡是1070到NVIDIA官网下载相应版本的驱动,安装时先禁用linux自带的驱动

sudo vim /etc/modprobe.d/blacklist-nouveau.conf

将驱动拉入黑名单,添加如下内容

blacklist nouveau
options nouveau modeset=0

更新,

sudo update-initramfs -u

之后是驱动的安装,首先切换至文本操作界面

Ctrl+Alt+F1即可

进入init 3 模式,即:

sudo init 3

输入密码后,关闭图形界面,

sudo service lightdm stop

进入驱动路径下

sudo sh ~/NVIDIA-Linux-x86_64-367.44.run  (版本路径自行修改)
在引导下安装成功后开启图形界面

sudo service lightdm start
回到图形界面,进入终端

输入nvidia-smi

出现,


输入nvidia-settings



则说明驱动安装成功。

2,安装cuda8

到官网下载系统对应版本的run文件,在runfile所在路径下执行

sudo sh cuda_8.0.27_linux.run
执行后一路让你阅读声明,回车即可,之后accept接受条款,到了让你选择是否安装驱动时,一定选否!!!

安装成功后出现,

===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /home/textminer
Please make sure that
– PATH includes /usr/local/cuda-8.0/bin
– LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing with the name of this run file:
sudo .run -silent -driver
Logfile is /opt/temp//cuda_install_6583.log

申明环境变量,

export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}


设置环境变量和动态链接库,

$ sudo gedit /etc/profile
打开的文件末尾加入:

export PATH=/usr/local/cuda/bin:$PATH

创建链接文件:

sudo gedit /etc/ld.so.conf.d/cuda.conf

文件中添加如下语句:

/usr/local/cuda/lib64
然后执行

sudo ldconfig

验证是否成功,测试cuda的sample

cd /usr/local/cuda-7.5/samples/1_Utilities/deviceQuery
make
sudo ./deviceQuery

出现gpu的一些信息则说明安装成功。


3,安装cudnn

到cudnn官网上注册帐号填入一些使用目的之类的信息后即可下载,注意下载相应cuda版本和系统版本的cudnn

我下载的cuda8下的cudnn5。1,linux library。下载后解压,进入cudnn5的include目录,复制cudnn头文件到安装的cuda下

sudo cp cudnn.h /usr/local/cuda/include/
可能会遇到cudnn h被锁的情况,修改权限
chmod 777 -R cudnn.h 
再复制就ok,

进入lib64下复制动态文件,建立链接,注意,生成链接时更据自己的cudnn/lib64下的libcudnn,so文件名自行修改

sudo cp lib* /usr/local/cuda/lib64/    #复制动态链接库
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.5    #删除原有动态文件
sudo ln -s libcudnn.so.5.0.5 libcudnn.so.5  #生成软衔接,注意自己版本的libcudnn。so文件后缀!可能不同
sudo ln -s libcudnn.so.5 libcudnn.so      #生成软链接

4,安装opencv3.1.0

官网上下载所需版本,解压到想安装的位置,

先安装ubuntu所需依赖包,

sudo apt-get install --assume-yes libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev 
libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev 
libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip

安装opencv需要的一些依赖项

sudo apt-get install build-essential cmake git

sudo apt-get install ffmpeg libopencv-dev libgtk-3-dev python-numpy python3-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev 
libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libv4l-dev libtbb-dev qtbase5-dev libfaac-dev 
libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip

cd到opencv文件夹下

sudo mkdir build   #新建一个build文件夹,编译的工程都在这个文件夹里
cd build/    
sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local  ..
成功会显示

-- Configuring done
-- Generating done
-- Build files have been written to: /home/ise/software/opencv-3.1.0/build

注如果前面cudnn链接没有配置正确,会报错关于so文件,此时回去将链接配置正确就好!

编译opencv同样在该路径下,-j为启用的线程数

make -j4
安装opencv到系统中

sudo make install
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

至此opencv安装完毕!

(1)有可能编译是会出现

ippicv_linux_20151201.tgz

下载不下来,导致安装失败,解决办法, 下载该文件按评论里的指导即可


(2)有可能报错

/home/usrname/opencv-3.0.0/modules/cudalegacy/src/graphcuts.cpp:120:54: error: ‘NppiGraphcutState’ has not been declared
     typedef NppStatus (*init_func_t)(NppiSize oSize, NppiGraphcutState** ppStat

此时,是因为次opencv不支持cuda8造成的,

解决方案:需要修改一处源码:
在graphcuts.cpp中将
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) 
改为
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)

5,安装caffe

首先安装依赖包

sudo apt-get update 
sudo apt-get install -y build-essential cmake git pkg-config 
 sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler 
 sudo apt-get install -y libatlas-base-dev 
 sudo apt-get install -y--no-install-recommends libboost-all-dev 
 sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev 
 sudo apt-get install -y python-pip 
 sudo apt-get install -y python-dev 
 sudo apt-get install -y python-numpy python-scipy  

下载caffe文件

git clone https://github.com/BVLC/caffe.git  //从github上git caffe
cd caffe //打开到刚刚git下来的caffe 
sudo cp Makefile.config.example Makefile.config   //将Makefile.config.example的内容复制到Makefile.config 
sudo gedit Makefile.config //打开Makefile.config文件
修改配置文件

## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).//使用了cudnn将此处注释去掉
 USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1

# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
#	You should not set this flag if you will be reading LMDBs with any
#	possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

# Uncomment if you're using OpenCV 3//此处为你的opencv版本
 OPENCV_VERSION := 3

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
		-gencode arch=compute_20,code=sm_21 \
		-gencode arch=compute_30,code=sm_30 \
		-gencode arch=compute_35,code=sm_35 \
		-gencode arch=compute_50,code=sm_50 \
		-gencode arch=compute_52,code=sm_52 \
		-gencode arch=compute_60,code=sm_60 \
		-gencode arch=compute_61,code=sm_61 \
		-gencode arch=compute_61,code=compute_61

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas //使用了OpenBlas 此处注释去掉,并改变下面的路径
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
 BLAS_INCLUDE := /home/alice/your/openblas 
 BLAS_LIB := /home/alice/your/openblas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \//我使用系统自带的python2
		/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		# $(ANACONDA_HOME)/include/python2.7 \
		# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)//使用pyhton3的在此处将注释去了。并自行填写python3的路径
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#                 /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
 WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include //16。04的系统此处要做修改,不过不推荐16的系统,坑!
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib


# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute


编译,安装


  
  
  1. make all -j4  
  2. cd ..
  3. make runtest  
  4. make pycaffe

至此安装完毕!







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值