验证系统是否具有支持CUDA的GPU
确定显卡型号:
查看系统属性,或者从命令行输入:
$ lspci | grep -i nvidia
只有NVIDIA显卡,并且能在 http://developer.nvidia.com/cuda-gpus 找到对应型号,那么该GPU就支持CUDA功能。
GPU和CUDA Toolkit的对应版本确认
支持GPU的驱动版本:
https://www.nvidia.cn/object/unix-cn.html
CUDA Toolkit版本与GPU版本对应信息:
信息来源:https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
相对较早的GPU,建议GPU支持的驱动版本和CUDA Toolkit版本都尽量选择对应较低的版本号,否则可能导致后面Caffe在运行时出现异常。
验证系统是否正在运行受支持的Linux版本
根据不同版本CUDA Toolkit,确定是否支持CUDA Toolkit。
例如CUDA Toolkit v8.0:
信息来源:https://docs.nvidia.com/cuda/archive/8.0/cuda-installation-guide-linux/index.html
验证系统是否已安装gcc
查看gcc版本:
$ gcc --version
验证系统是否安装了正确的内核头文件和开发包。
查看正在运行的分发和版本号:
$ uname -m && cat /etc/*release
或者,过运行以下命令找到系统正在运行的内核版本:
$ uname -r
如果没有任何信息显示,可以使用以下命令安装当前运行的内核的内核头文件和开发包:
$ sudo apt-get install linux-headers - $(uname -r)
虽然在安装CUDA Toolkit会提供对应的驱动版本,但仍建议自行查找合适的驱动安装,因为CUDA Toolkit自带的驱动不一定是适合当前GPU的版本。
需要下载以下package:
GPU驱动:NVIDIA-Linux-x86_64-390.87.run
禁用Nouveau
要安装显示驱动程序,必须首先禁用Nouveau驱动程序。Linux的每个发行版都有不同的方法来禁用Nouveau。
创建文件:
$ sudo vi /etc/modprobe.d/blacklist-nouveau.conf
输入一下信息并保存:
blacklist nouveau
options nouveau modeset=0
重新生成内核initramfs:
$ sudo update-initramfs -u
输入一下命令,查看是否禁用成功:
$ lspci | grep nouveau
没有任何信息显示,则表示禁用成功。如果此方法不能禁用成功,则可以选择以下方式:
直接移除这个驱动(备份出来):
$ mv /lib/modules/3.0.0-12-generic/kernel/drivers/gpu/drm/nouveau/nouveau.ko /lib/modules/3.0.0-12-generic/kernel/drivers/gpu/drm/nouveau/nouveau.ko.org
重新加载一下
$ sudo update-initramfs -u
重启:
$ sudo reboot
显示器字体有明显变大模糊的情况。
安装驱动
执行安装:
$ sudo sh NVIDIA-Linux-x86_64-390.87.run
运行安装文件过程中如果提示you appear to be running an x server;
的类似错误,请运行以下命令进行关闭:
$ sudo /etc/init.d/lightdm stop
检查是否安装成功:
$ cat /proc/driver/nvidia/version
显示如下信息:
则安装成功。
CUDA Toolkit的安装有多种方式,我们采用最可控的一种,runfile install(运行文件安装)。
需要下载以下package:
CUDA Toolkit工具包:cuda_8.0.61_375.26_linux.run
官方建议GPU算力在3.0以下,不要安装Cudnn。因此,我们这次的环境搭建中不支持Cudnn(GT610算力为2.1,可在 http://developer.nvidia.com/cuda-gpus 查询相关信息)。
确保显卡安装成功的前提下,进行CUDA Toolkit安装。
$ sudo sh cuda_8.0.61_375.26_linux.run --no-opengl-libs //不安装opengl
$ sudo vi ~/.bashrc
将如下内容保存至.bashrc:
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
执行生效:
$ source ~/.bashrc
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
显示Result = PASS
,则表示安装成功:
如果没有成功,则需要卸载后重新install。
以上安装内容,参考 https://docs.nvidia.com/cuda/archive/8.0/cuda-installation-guide-linux/index.html#runfile 第4章节和 https://blog.csdn.net/qq473179304/article/details/79444609 。
因为需要包含opencv_contrib的一些模块,所以OpenCV采用源码编译安装。
鉴于OpenCV对FFmpeg的依赖,需要先安装FFmpeg。
$ git clone https://github.com/FFmpeg/FFmpeg.git
$ git checkout n3.4.5
// checkout到一个可以支持opencv3.4.3的任一版本
$ ./configure --enable-shared
// 需要编译成静态库
$ make
$ sudo make install
opencv_contrib模块源码克隆:git clone https://github.com/opencv/opencv_contrib.git
切换到指定版本:
cd ~/opencv_contrib
// 进入到opencv_contrib源码路径
git checkout 3.4.3
// 切换到分支3.4.3
[注意]:这里必须要与OpenCV的源码版本保持一致
OpenCV模块源码克隆:git clone https://github.com/opencv/opencv.git
依赖包安装:
$ 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 libjasper-dev libdc1394-22-dev
按顺序执行以下命令安装:
$ cd ~/opencv
// 进入到OpenCV源码路径
$ git checkout 3.4.3
// 切换到3.4.3分支,同时opencv_contrib也需要切换到相同分支
$ mkdir build
// 创建构建目录build
$ cd build
$ sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/ -D WITH_CUDA=ON -D WITH_CUBLAS=ON -D CUDA_FAST_MATH=ON -D WITH_CUFFT=ON -D WITH_NVCUVID=ON -D WITH_V4L=ON -D WITH_LIBV4L=ON -D WITH_OPENGL=ON -D WITH_FFMPEG=ON -D OPENCV_EXTRA_MODULES_PATH=/home/alpha/Downloads/opencv_contrib/modules ..
OPENCV_EXTRA_MODULES_PATH设置为opencv_contrib的modules文件夹路径;CMAKE_INSTALL_PREFIX可以指定OpenCV的安装路径。
OpenCV生成信息:
-- Version control: 3.4.3
--
-- Extra modules:
-- Location (extra): /home/alpha_gpu/Downloads/opencv_contrib/modules
-- Version control (extra): 3.4.3
--
-- Platform:
-- Timestamp: 2018-11-20T08:00:14Z
-- Host: Linux 4.8.0-36-generic x86_64
-- CMake: 3.5.1
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: Release
--
-- CPU/HW features:
-- Baseline: SSE SSE2 SSE3
-- requested: SSE3
-- Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
-- requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
-- SSE4_1 (5 files): + SSSE3 SSE4_1
-- SSE4_2 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2
-- FP16 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
-- AVX (6 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
-- AVX2 (11 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
-- AVX512_SKX (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX
--
-- C/C++:
-- Built as dynamic libs?: YES
-- C++ Compiler: /usr/bin/c++ (ver 5.4.0)
-- C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
-- C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
-- C Compiler: /usr/bin/cc
-- C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
-- C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
-- Linker flags (Release):
-- Linker flags (Debug):
-- ccache: NO
-- Precompiled headers: YES
-- Extra dependencies: dl m pthread rt cudart nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cufft -L/usr/local/cuda/lib64
-- 3rdparty dependencies:
--
-- OpenCV modules:
-- To be built: aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
-- Disabled: js world
-- Disabled by dependency: -
-- Unavailable: cnn_3dobj cvv hdf java matlab ovis python2 python3 sfm viz
-- Applications: tests perf_tests apps
-- Documentation: NO
-- Non-free algorithms: NO
--
-- GUI:
-- GTK+: YES (ver 2.24.30)
-- GThread : YES (ver 2.48.2)
-- GtkGlExt: NO
-- OpenGL support: NO
-- VTK support: NO
--
-- Media I/O:
-- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
-- JPEG: libjpeg-turbo (ver 1.5.3-62)
-- WEBP: build (ver encoder: 0x020e)
-- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
-- TIFF: build (ver 42 - 4.0.9)
-- JPEG 2000: build (ver 1.900.1)
-- OpenEXR: build (ver 1.7.1)
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
--
-- Video I/O:
-- DC1394: NO
-- FFMPEG: YES
-- avcodec: YES (ver 57.107.100)
-- avformat: YES (ver 57.83.100)
-- avutil: YES (ver 55.78.100)
-- swscale: YES (ver 4.8.100)
-- avresample: NO
-- GStreamer: NO
-- libv4l/libv4l2: NO
-- v4l/v4l2: linux/videodev2.h
--
-- Parallel framework: pthreads
--
-- Trace: YES (with Intel ITT)
--
-- Other third-party libraries:
-- Intel IPP: 2017.0.3 [2017.0.3]
-- at: /home/alpha_gpu/Downloads/opencv/build/3rdparty/ippicv/ippicv_lnx
-- Intel IPP IW: sources (2017.0.3)
-- at: /home/alpha_gpu/Downloads/opencv/build/3rdparty/ippicv/ippiw_lnx
-- Lapack: NO
-- Eigen: NO
-- Custom HAL: NO
-- Protobuf: build (3.5.1)
--
-- NVIDIA CUDA: YES (ver 8.0, CUFFT CUBLAS NVCUVID FAST_MATH)
-- NVIDIA GPU arch: 20 30 35 37 50 52 60 61
-- NVIDIA PTX archs:
--
-- OpenCL: YES (no extra features)
-- Include path: /home/alpha_gpu/Downloads/opencv/3rdparty/include/opencl/1.2
-- Link libraries: Dynamic load
--
-- Python (for build): /usr/bin/python2.7
--
-- Java:
-- ant: NO
-- JNI: NO
-- Java wrappers: NO
-- Java tests: NO
--
-- Matlab: NO
--
-- Install to: /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alpha_gpu/Downloads/opencv/build
出现Configuring done
和Generating done
且没有提示错误
的情况下,则cmake成功。同时,可以查看信息OpenCV modules
的To be built:
是否包含所有需要编译的模块。
继续执行:
$ make
//这里执行后需要等待一段时间,但可以添加-j8选项,提高编译速度
$ sudo make install
// 执行安装
安装完成后,可查看安装目录下是否生成了libopencv*.so等文件。
$ ls /usr/local/lib/libopencv*
/usr/local/lib/libopencv_aruco.so /usr/local/lib/libopencv_highgui.so.3.4.3
/usr/local/lib/libopencv_aruco.so.3.4 /usr/local/lib/libopencv_imgcodecs.so
/usr/local/lib/libopencv_aruco.so.3.4.3 /usr/local/lib/libopencv_imgcodecs.so.3.4
/usr/local/lib/libopencv_bgsegm.so /usr/local/lib/libopencv_imgcodecs.so.3.4.3
/usr/local/lib/libopencv_bgsegm.so.3.4 /usr/local/lib/libopencv_img_hash.so
/usr/local/lib/libopencv_bgsegm.so.3.4.3 /usr/local/lib/libopencv_img_hash.so.3.4
/usr/local/lib/libopencv_bioinspired.so /usr/local/lib/libopencv_img_hash.so.3.4.3
/usr/local/lib/libopencv_bioinspired.so.3.4 /usr/local/lib/libopencv_imgproc.so
/usr/local/lib/libopencv_bioinspired.so.3.4.3 /usr/local/lib/libopencv_imgproc.so.3.4
/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_imgproc.so.3.4.3
/usr/local/lib/libopencv_calib3d.so.3.4 /usr/local/lib/libopencv_line_descriptor.so
/usr/local/lib/libopencv_calib3d.so.3.4.3 /usr/local/lib/libopencv_line_descriptor.so.3.4
/usr/local/lib/libopencv_ccalib.so /usr/local/lib/libopencv_line_descriptor.so.3.4.3
/usr/local/lib/libopencv_ccalib.so.3.4 /usr/local/lib/libopencv_ml.so
/usr/local/lib/libopencv_ccalib.so.3.4.3 /usr/local/lib/libopencv_ml.so.3.4
/usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_ml.so.3.4.3
/usr/local/lib/libopencv_core.so.3.4 /usr/local/lib/libopencv_objdetect.so
/usr/local/lib/libopencv_core.so.3.4.3 /usr/local/lib/libopencv_objdetect.so.3.4
/usr/local/lib/libopencv_cudaarithm.so /usr/local/lib/libopencv_objdetect.so.3.4.3
/usr/local/lib/libopencv_cudaarithm.so.3.4 /usr/local/lib/libopencv_optflow.so
/usr/local/lib/libopencv_cudaarithm.so.3.4.3 /usr/local/lib/libopencv_optflow.so.3.4
/usr/local/lib/libopencv_cudabgsegm.so /usr/local/lib/libopencv_optflow.so.3.4.3
/usr/local/lib/libopencv_cudabgsegm.so.3.4 /usr/local/lib/libopencv_phase_unwrapping.so
/usr/local/lib/libopencv_cudabgsegm.so.3.4.3 /usr/local/lib/libopencv_phase_unwrapping.so.3.4
/usr/local/lib/libopencv_cudacodec.so /usr/local/lib/libopencv_phase_unwrapping.so.3.4.3
/usr/local/lib/libopencv_cudacodec.so.3.4 /usr/local/lib/libopencv_photo.so
/usr/local/lib/libopencv_cudacodec.so.3.4.3 /usr/local/lib/libopencv_photo.so.3.4
/usr/local/lib/libopencv_cudafeatures2d.so /usr/local/lib/libopencv_photo.so.3.4.3
/usr/local/lib/libopencv_cudafeatures2d.so.3.4 /usr/local/lib/libopencv_plot.so
/usr/local/lib/libopencv_cudafeatures2d.so.3.4.3 /usr/local/lib/libopencv_plot.so.3.4
/usr/local/lib/libopencv_cudafilters.so /usr/local/lib/libopencv_plot.so.3.4.3
/usr/local/lib/libopencv_cudafilters.so.3.4 /usr/local/lib/libopencv_reg.so
/usr/local/lib/libopencv_cudafilters.so.3.4.3 /usr/local/lib/libopencv_reg.so.3.4
/usr/local/lib/libopencv_cudaimgproc.so /usr/local/lib/libopencv_reg.so.3.4.3
/usr/local/lib/libopencv_cudaimgproc.so.3.4 /usr/local/lib/libopencv_rgbd.so
/usr/local/lib/libopencv_cudaimgproc.so.3.4.3 /usr/local/lib/libopencv_rgbd.so.3.4
/usr/local/lib/libopencv_cudalegacy.so /usr/local/lib/libopencv_rgbd.so.3.4.3
/usr/local/lib/libopencv_cudalegacy.so.3.4 /usr/local/lib/libopencv_saliency.so
/usr/local/lib/libopencv_cudalegacy.so.3.4.3 /usr/local/lib/libopencv_saliency.so.3.4
/usr/local/lib/libopencv_cudaobjdetect.so /usr/local/lib/libopencv_saliency.so.3.4.3
/usr/local/lib/libopencv_cudaobjdetect.so.3.4 /usr/local/lib/libopencv_shape.so
/usr/local/lib/libopencv_cudaobjdetect.so.3.4.3 /usr/local/lib/libopencv_shape.so.3.4
/usr/local/lib/libopencv_cudaoptflow.so /usr/local/lib/libopencv_shape.so.3.4.3
/usr/local/lib/libopencv_cudaoptflow.so.3.4 /usr/local/lib/libopencv_stereo.so
/usr/local/lib/libopencv_cudaoptflow.so.3.4.3 /usr/local/lib/libopencv_stereo.so.3.4
/usr/local/lib/libopencv_cudastereo.so /usr/local/lib/libopencv_stereo.so.3.4.3
/usr/local/lib/libopencv_cudastereo.so.3.4 /usr/local/lib/libopencv_stitching.so
/usr/local/lib/libopencv_cudastereo.so.3.4.3 /usr/local/lib/libopencv_stitching.so.3.4
/usr/local/lib/libopencv_cudawarping.so /usr/local/lib/libopencv_stitching.so.3.4.3
/usr/local/lib/libopencv_cudawarping.so.3.4 /usr/local/lib/libopencv_structured_light.so
/usr/local/lib/libopencv_cudawarping.so.3.4.3 /usr/local/lib/libopencv_structured_light.so.3.4
/usr/local/lib/libopencv_cudev.so /usr/local/lib/libopencv_structured_light.so.3.4.3
/usr/local/lib/libopencv_cudev.so.3.4 /usr/local/lib/libopencv_superres.so
/usr/local/lib/libopencv_cudev.so.3.4.3 /usr/local/lib/libopencv_superres.so.3.4
/usr/local/lib/libopencv_datasets.so /usr/local/lib/libopencv_superres.so.3.4.3
/usr/local/lib/libopencv_datasets.so.3.4 /usr/local/lib/libopencv_surface_matching.so
/usr/local/lib/libopencv_datasets.so.3.4.3 /usr/local/lib/libopencv_surface_matching.so.3.4
/usr/local/lib/libopencv_dnn_objdetect.so /usr/local/lib/libopencv_surface_matching.so.3.4.3
/usr/local/lib/libopencv_dnn_objdetect.so.3.4 /usr/local/lib/libopencv_text.so
/usr/local/lib/libopencv_dnn_objdetect.so.3.4.3 /usr/local/lib/libopencv_text.so.3.4
/usr/local/lib/libopencv_dnn.so /usr/local/lib/libopencv_text.so.3.4.3
/usr/local/lib/libopencv_dnn.so.3.4 /usr/local/lib/libopencv_tracking.so
/usr/local/lib/libopencv_dnn.so.3.4.3 /usr/local/lib/libopencv_tracking.so.3.4
/usr/local/lib/libopencv_dpm.so /usr/local/lib/libopencv_tracking.so.3.4.3
/usr/local/lib/libopencv_dpm.so.3.4 /usr/local/lib/libopencv_videoio.so
/usr/local/lib/libopencv_dpm.so.3.4.3 /usr/local/lib/libopencv_videoio.so.3.4
/usr/local/lib/libopencv_face.so /usr/local/lib/libopencv_videoio.so.3.4.3
/usr/local/lib/libopencv_face.so.3.4 /usr/local/lib/libopencv_video.so
/usr/local/lib/libopencv_face.so.3.4.3 /usr/local/lib/libopencv_video.so.3.4
/usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_video.so.3.4.3
/usr/local/lib/libopencv_features2d.so.3.4 /usr/local/lib/libopencv_videostab.so
/usr/local/lib/libopencv_features2d.so.3.4.3 /usr/local/lib/libopencv_videostab.so.3.4
/usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_videostab.so.3.4.3
/usr/local/lib/libopencv_flann.so.3.4 /usr/local/lib/libopencv_xfeatures2d.so
/usr/local/lib/libopencv_flann.so.3.4.3 /usr/local/lib/libopencv_xfeatures2d.so.3.4
/usr/local/lib/libopencv_freetype.so /usr/local/lib/libopencv_xfeatures2d.so.3.4.3
/usr/local/lib/libopencv_freetype.so.3.4 /usr/local/lib/libopencv_ximgproc.so
/usr/local/lib/libopencv_freetype.so.3.4.3 /usr/local/lib/libopencv_ximgproc.so.3.4
/usr/local/lib/libopencv_fuzzy.so /usr/local/lib/libopencv_ximgproc.so.3.4.3
/usr/local/lib/libopencv_fuzzy.so.3.4 /usr/local/lib/libopencv_xobjdetect.so
/usr/local/lib/libopencv_fuzzy.so.3.4.3 /usr/local/lib/libopencv_xobjdetect.so.3.4
/usr/local/lib/libopencv_hfs.so /usr/local/lib/libopencv_xobjdetect.so.3.4.3
/usr/local/lib/libopencv_hfs.so.3.4 /usr/local/lib/libopencv_xphoto.so
/usr/local/lib/libopencv_hfs.so.3.4.3 /usr/local/lib/libopencv_xphoto.so.3.4
/usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_xphoto.so.3.4.3
/usr/local/lib/libopencv_highgui.so.3.4
在安装Caffe之前,需要将以下依赖项依次安装:
依次执行
$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
$ sudo apt-get install --no-install-recommends libboost-all-dev
$ sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
$ sudo apt-get install git cmake build-essential
$ git clone https://github.com/BVLC/caffe.git
$ cd ~/caffe
// 进入到Caffe源码目录
$ sudo cp Makefile.config.example Makefile.config
$ sudo vi Makefile.config
// 编辑Makefile.config文件
Makefile.config文件有很多选项配置,需要根据当前使用场景进行配置。我们只进行以下配置修改:
打开OPENCV_VERSION选项:
#OPENCV_VERSION := 3
修改为OPENCV_VERSION := 3
打开 WITH_PYTHON_LAYER选项:
#WITH_PYTHON_LAYER := 1
修改为WITH_PYTHON_LAYER := 1
为INCLUDE_DIRS和LIBRARY_DIRS添加路径:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
修改为:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /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
找到CUDA_ARCH,将其中包含-gencode arch=compute_20
的行删掉。
修改前:
修改后:
NVCCFLAGS
添加编译选项: 由:
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
改为:
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
LIBRARIES
: 将:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
改为:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
$ mkdir build
$ cd build
$ sudo cmake ..
生成以下信息:
-- General:
-- Version : 1.0.0-rc3
-- Git : rc2-1139-gca8c158e-dirty
-- System : Linux
-- C++ compiler : /usr/bin/c++
-- Release CXX flags : -O3 -DNDEBUG -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
-- Debug CXX flags : -g -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
-- Build type : Release
--
-- BUILD_SHARED_LIBS : ON
-- BUILD_python : ON
-- BUILD_matlab : OFF
-- BUILD_docs : ON
-- CPU_ONLY : OFF
-- USE_OPENCV : ON
-- USE_LEVELDB : ON
-- USE_LMDB : ON
-- ALLOW_LMDB_NOLOCK : OFF
--
-- Dependencies:
-- BLAS : Yes (Atlas)
-- Boost : Yes (ver. 1.65)
-- glog : Yes
-- gflags : Yes
-- protobuf : Yes (ver. 3.0.0)
-- lmdb : Yes (ver. 0.9.21)
-- LevelDB : Yes (ver. 1.20)
-- Snappy : Yes (ver. ..)
-- OpenCV : Yes (ver. 3.4.3)
-- CUDA : Yes (ver. 8.0)
--
-- NVIDIA CUDA:
-- Target GPU(s) : Auto
-- GPU arch(s) : sm_21
-- cuDNN : Not found
--
-- Python:
-- Interpreter : /usr/bin/python2.7 (ver. 2.7.15)
-- Libraries : /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.15rc1)
-- NumPy : /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.13.3)
--
-- Documentaion:
-- Doxygen : /usr/bin/doxygen (1.8.13)
-- config_file : /home/alpha/Downloads/weiliu89-caffe/.Doxyfile
--
-- Install:
-- Install path : /home/alpha/Downloads/weiliu89-caffe/.build_release/install
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alpha/Downloads/weiliu89-caffe/.build_release
cmake成功后,则继续执行:
$ sudo make all
//可以加-j8选项,加速编译
$ sudo make pycaffe
$ sudo make runtest
//可以加-j8选项,加速编译
如若需要配置caffe ssd的环境,则可以在配置了caffe的基础上,在对caffe ssd进行安装配置,具体可参考: https://github.com/weiliu89/caffe/tree/ssd#installation
解决方法:
$ vi caffe/CMakefilelist.txt
将:
if(UNIX OR APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
endif()
改为:
if(UNIX OR APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -std=c++11")
endif()
python-skimage包依赖于matplotlib,scipy,pil,numpy和six。
首先安装依赖包:
sudo apt-get install python-matplotlib python-numpy python-pil python-scipy
sudo apt-get install build-essential cython
安装skimage包:
sudo apt-get install python-skimage
参考:https://blog.csdn.net/dc1994dc/article/details/79162886