Caffe 版 MobileNet-Yolo配置

項目工程鏈接: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
輸出:

 對編譯後的結果例子進行測試

運行demo

切到項目目錄下(替換成你的),運行如下指令:

> 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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章