项目工程链接:MobileNet-YOLO
环境:centos7,cuda9.0,cudnn7.5,OpenCV3.3.1
1.安装opencv的依赖项
#首先切换到root权限下:
$su
$ yum install apt-get install build-essential
$ yum install apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ yum install apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
#ubuntu指令请参考以下:
$ 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
安装OpenCV3.3.1
项目推荐指令:
#download opencv-3.3.1 from web
$ cd opencv-3.3.1
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
$ make -j8
$ sudo make install
如果你事先已经安装过opencv其他版本的,而且安装路径也是/usr/local的,你又不想直接覆盖的话,请参考该文章linux下多个OpenCV版本的安装,
2. 安装caffe的依赖项:
#其中ubuntu的安装指令为:
$ sudo apt-get install libatlas-base-dev libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libboost-all-dev libgflags-dev libgoogle-glog-dev liblmdb-dev libyaml-dev
$ sudo apt-get install python-numpy python-setuptools python-pip cython python-skimage python-protobuf
$ sudo pip install easydict PyYAML
#而centos的话指令有些差异,你可以暂且使用如下操作,查看有报错的安装对应的依赖:
$su
$ yum install libatlas-base-dev libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libboost-all-dev libgflags-dev libgoogle-glog-dev liblmdb-dev libyaml-dev
$ yum install python-numpy python-setuptools python-pip cython python-skimage python-protobuf
$ yum install easydict PyYAML
完成以上依赖项的安装后进行编译。
#下载工程
> git clone https://github.com/eric612/MobileNet-YOLO.git
#切换到解压后的工程文件夹下
> cd $MobileNet-YOLO_root/
#创建用于存放编译中间过程产生的文件的文件夹
> mkdir build
> cd build
> cmake ..
> make -j4
> make pycaffe
如果你在输入cmake ..时提示如下错误: Could NOT find Atlas (missing: Atlas_LAPACK_LIBRARY)
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- system
-- thread
-- filesystem
-- Found GFlags: /usr/include
-- Found gflags (include: /usr/include, library: /usr/lib64/libgflags.so)
-- Found Glog: /usr/include
-- Found glog (include: /usr/include, library: /usr/lib64/libglog.so)
-- Found Protobuf: /usr/local/lib/libprotobuf.so;-lpthread (found version "3.5.0")
-- Found PROTOBUF Compiler: /usr/local/bin/protoc
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- HDF5: Using hdf5 compiler wrapper to determine CXX configuration
-- Found HDF5: /usr/lib64/libhdf5_cpp.so;/usr/lib64/libhdf5.so;/usr/lib64/libsz.so;/usr/lib64/libz.so;/usr/lib64/libdl.so;/usr/lib64/libm.so (found version "1.8.12") found components: HL
-- Found LMDB: /usr/include
-- Found lmdb (include: /usr/include, library: /usr/lib64/liblmdb.so)
-- CUDA detected: 8.0
-- Added CUDA NVCC flags for: sm_61
-- OpenCV found (/usr/local/opencv-2.4.13)
CMake Error at /usr/local/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find Atlas (missing: Atlas_LAPACK_LIBRARY)
Call Stack (most recent call first):
/usr/local/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
就是缺少了这么个库,需要你去安装,对于centos情况,需要安装OpenBLAS库,对于ubuntu情况,请安装ATLAS BLAS库(可使用命令sudo apt install libatlas-base-dev),这两个库其实都是用于向量和矩阵运算是数值计算的(两者的描述请参考:CMakelist中涉及的BLAS简介)
centos下(切到root下安装):$yum intall openblas
还有个问题:上面代码中还提示OpenCV found但是路径是/usr/local/opencv-2.4.13,这个是我安装的旧的版本的路径,我需要给cmake默认寻找的路径重新指定下opencv的路径才行。
在完成了OpenBLAS(由于我的是centos系统)安装后重新进行cmake,指令更改如下:
[root@localhost build]# cmake .. -DBLAS=open -DOpenCV_DIR=/usr/local/opencv-3.3.1/build
如果不指定BLAS=open的话,默认是ATLAS BLAS库,即BLAS=atlas。
这时候cmake对话窗口输出如下内容:
[root@localhost build]# cmake .. -DBLAS=open -DOpenCV_DIR=/usr/local/opencv-3.3.1/build
CMake Warning at /usr/local/share/cmake-3.6/Modules/FindBoost.cmake:743 (message):
Imported targets not available for Boost version 106600
Call Stack (most recent call first):
/usr/local/share/cmake-3.6/Modules/FindBoost.cmake:842 (_Boost_COMPONENT_DEPENDENCIES)
/usr/local/share/cmake-3.6/Modules/FindBoost.cmake:1395 (_Boost_MISSING_DEPENDENCIES)
cmake/Dependencies.cmake:8 (find_package)
CMakeLists.txt:50 (include)
CMake Warning at /usr/local/share/cmake-3.6/Modules/FindBoost.cmake:743 (message):
Imported targets not available for Boost version 106600
Call Stack (most recent call first):
/usr/local/share/cmake-3.6/Modules/FindBoost.cmake:842 (_Boost_COMPONENT_DEPENDENCIES)
/usr/local/share/cmake-3.6/Modules/FindBoost.cmake:1395 (_Boost_MISSING_DEPENDENCIES)
cmake/Dependencies.cmake:8 (find_package)
CMakeLists.txt:50 (include)
CMake Warning at /usr/local/share/cmake-3.6/Modules/FindBoost.cmake:743 (message):
Imported targets not available for Boost version 106600
Call Stack (most recent call first):
/usr/local/share/cmake-3.6/Modules/FindBoost.cmake:842 (_Boost_COMPONENT_DEPENDENCIES)
/usr/local/share/cmake-3.6/Modules/FindBoost.cmake:1395 (_Boost_MISSING_DEPENDENCIES)
cmake/Dependencies.cmake:8 (find_package)
CMakeLists.txt:50 (include)
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- system
-- thread
-- filesystem
-- Found gflags (include: /usr/include, library: /usr/lib64/libgflags.so)
-- Found glog (include: /usr/include, library: /usr/lib64/libglog.so)
-- Found PROTOBUF Compiler: /usr/local/bin/protoc
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- HDF5: Using hdf5 compiler wrapper to determine CXX configuration
-- Found lmdb (include: /usr/include, library: /usr/lib64/liblmdb.so)
-- CUDA detected: 8.0
-- Added CUDA NVCC flags for: sm_61
-- OpenCV found (/usr/local/opencv-3.3.1/build)
-- Found OpenBLAS libraries: /usr/lib64/libopenblas.so
-- Found OpenBLAS include: /usr/include
-- Found PythonInterp: /bin/python2.7 (found suitable version "2.7.5", minimum required is "2.7")
-- Found PythonLibs: //lib64/libpython2.7.so (found suitable version "2.7.5", minimum required is "2.7")
-- Found NumPy: /usr/lib64/python2.7/site-packages/numpy/core/include (found suitable version "1.15.4", minimum required is "1.7.1")
-- NumPy ver. 1.15.4 found (include: /usr/lib64/python2.7/site-packages/numpy/core/include)
CMake Warning at /usr/local/share/cmake-3.6/Modules/FindBoost.cmake:743 (message):
Imported targets not available for Boost version 106600
Call Stack (most recent call first):
/usr/local/share/cmake-3.6/Modules/FindBoost.cmake:842 (_Boost_COMPONENT_DEPENDENCIES)
/usr/local/share/cmake-3.6/Modules/FindBoost.cmake:1395 (_Boost_MISSING_DEPENDENCIES)
cmake/Dependencies.cmake:172 (find_package)
CMakeLists.txt:50 (include)
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- python
-- Found Doxygen: /bin/doxygen (found version "1.8.5")
-- Detected Doxygen OUTPUT_DIRECTORY: ./doxygen/
-- Found Git: /bin/git (found version "1.8.3.1")
--
-- ******************* Caffe Configuration Summary *******************
-- General:
-- Version : 1.0.0
-- Git : unknown
-- System : Linux
-- C++ compiler : /usr/bin/g++
-- 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 : OFF
-- USE_LMDB : ON
-- USE_NCCL : OFF
-- ALLOW_LMDB_NOLOCK : OFF
--
-- Dependencies:
-- BLAS : Yes (open)
-- Boost : Yes (ver. 1.66)
-- glog : Yes
-- gflags : Yes
-- protobuf : Yes (ver. 3.5.0)
-- lmdb : Yes (ver. 0.9.22)
-- OpenCV : Yes (ver. 3.3.1)
-- CUDA : Yes (ver. 8.0)
--
-- NVIDIA CUDA:
-- Target GPU(s) : Auto
-- GPU arch(s) : sm_61
-- cuDNN : Disabled
--
-- Python:
-- Interpreter : /bin/python2.7 (ver. 2.7.5)
-- Libraries : //lib64/libpython2.7.so (ver 2.7.5)
-- NumPy : /usr/lib64/python2.7/site-packages/numpy/core/include (ver 1.15.4)
--
-- Documentaion:
-- Doxygen : /bin/doxygen (1.8.5)
-- config_file : /home/chensq/MobileNet-YOLO-master/.Doxyfile
--
-- Install:
-- Install path : /home/chensq/MobileNet-YOLO-master/build/install
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/chensq/MobileNet-YOLO-master/build
生成Makefile文件后接着是输入make -j4指令,会生成yolo_detect和ssd_detect等可执行文件(路径在项目路径/build/examples/yolo 和ssd中)
最后是输入指令make pycaffe,
[root@localhost build]# make pycaffe
输出:
对编译后的结果例子进行测试
切到项目目录下(替换成你的),运行如下指令:
> cd $caffe_root/
> sh demo_yolo_lite.sh
终端对话框会显示诸如如下的内容:
15 0.975348 192 106 271 365
12 0.960033 67 260 210 358
13 0.640205 390 133 596 343
Predicted in 0.000000 seconds.
I0225 11:03:24.597574 17895 yolo_detect.cpp:482] Computing time: 5 ms.
即会列出检测的label ID号,置信度信息,框坐标,检测时间等信息。
Enjoy It.
PS:错误集整理:
错误一:如果在make时提示错误如下:
请尝试修改CMakeLists.txt,在文件中的这句
SET(CMAKE_CXX_FLAGS " ")变为SET(CMAKE_CXX_FLAGS "-std=c++11"),然后make clean下,重新cmake;