Ubuntu + CUDA9.1 + CUDNN7.1.2 + OpenCV3.4.1 + contrib-master +CA

黑客与画家 2018-04-05

安装ubuntu 14.04时赞美Rufus,过程参考 https://www.cnblogs.com/willnote/p/6725594.html


-----------------------------------------------------------
!保!障!网!络!通!畅!
-----------------------------------------------------------
安装显卡驱动
sudo gedit /etc/modprobe.d/blacklist-nouveau.conf
blacklist nouveau
sudo update-initramfs -u
sudo add-apt-repository ppa:xorg-edgers/ppa
sudo apt-get update
关机
开机

ctrl+alt+F1进入命令行模式,登录用户。

sudo apt-get remove --purge nvidia*
sudo service lightdm stop
sudo apt-get install nvidia-390 #for GTX850M,注意检查自己版本型号,详见NVIDIA官网
sudo service lightdm start
重启
sudo nvidia-smi #确认输出了有效信息
-----------------------------------------------------------
-----------------------------------------------------------

安装依赖包

sudo apt-get install --no-install-recommends libboost-all-dev

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libopenblas-dev liblapack-dev libatlas-base-devlibgflags-dev libgoogle-glog-dev liblmdb-dev -y

-----------------------------------------------------------
-----------------------------------------------------------
安装cuda
显卡所支持的CUDA, CUDNN版本,参考NVIDIA官网
sudo sh ./cuda_9.1.85_387.26_linux.runsudo sh ./cuda_9.1.85.1_linux.run
sudo sh ./cuda_9.1.85.2_linux.run
sudo sh ./cuda_9.1.85.3_linux.run

sudo gedit~/.bashrc
export PATH=/usr/local/cuda-[版本号]/bin${PATH:+:${PATH}}

export LD_LIBRARY_PATH=/usr/local/cuda-[版本号]/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

-----------------------------------------------------------
测试cuda

cd [NVIDIA_CUDA_SAMPLES]/1_Utilities/deviceQuery
sudo make
./deviceQuery #确认输出了有效的显卡信息

-----------------------------------------------------------
sudo cp [cudnn]/cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp [cudnn]/cuda/lib64/lib* /usr/local/cuda/lib64/

cd /usr/local/cuda/lib64/sudo rm -rf libcudnn.so libcudnn.so.[主版本号]
sudo ln -s libcudnn.so.[全版本号] libcudnn.so.[主版本号]
sudo ln -s libcudnn.so.[主版本号] libcudnn.so
sudo ldconfig
-----------------------------------------------------------
-----------------------------------------------------------
安装opencv-3.4.1 + contrib-master
contrib解压至[opencv]/modules/
下载ippicv_2017u3_lnx_intel64_general_20170822.tgz至 [opencv]/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e 改名为 4e0352ce96473837b1d671ce87f17359-ippicv_2017u3_lnx_intel64_general_20170822.tgz


cmake:
BUILD_DOCSBUILD_JPEGBUILD_PNG BUILD_opencv_worldOPENCV_EXTRA_MODULES_PATH([contrib]/modules)
configure两次确认无误(或者相关BLAS的错误,目前暂未发现负面影响)后generate


cd [opencv]/build
sudo make all -j[内核数]
sudo make install -j[内核数]
sudo gedit /etc/ld.so.conf.d/opencv.conf
/usr/local/lib/x86_64-linux-gnu
sudo ldconfig
-----------------------------------------------------------
-----------------------------------------------------------
安装caffe
复制caffe/MakeFile.config.example为MakeFile.config

USE_CUDNN := 1

USE_OPENCV := 1

# Whatever else you find you need goes here.

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/include/opencv /usr/local/include/opencv2 /usr/include/hdf5/serial

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial /usr/local/lib/x86_64-linux-gnu

CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \

#-gencode arch=compute_20,code=sm_21 \


MakeFile注意把空格换回制表符:

ifeq ($(USE_OPENCV), 1)

#LIBRARIES += opencv_core opencv_highgui opencv_imgproc

#ifeq ($(OPENCV_VERSION), 3)

#LIBRARIES += opencv_imgcodecs

#endif

LIBRARIES += opencv_world

endif

make all -j[CPU内核数]
sudo gedit /etc/ld.so.conf.d/caffe.conf
/usr/local/cuda/lib64
sudo ldconfig

-----------------------------------------------------------
-----------------------------------------------------------
测试caffe

cd [caffe]

sudo sh data/mnist/get_mnist.sh

sudo sh examples/mnist/create_mnist.sh
sudo sh examples/mnist/train_lenet.sh

-----------------------------------------------------------

-----------------------------------------------------------

参考http://www.cnblogs.com/denny402/p/5083300.html开工

相关推荐