Ubuntu16.04LTS搭建Doppia行人检测库环境

来源:互联网 发布:拼图软件哪个好 编辑:程序博客网 时间:2024/06/08 17:58

前言

我最近读了Alex的另一篇名为Real-Time Pedestrian Detection With Deep Network Cascades文章,正尝试用cuda-convnet2与doppia重现这篇文章的效果。由于我的GPU架构对cuda-convnet2不大兼容,只好考虑使用Tensorflow构建里面的微型深度网络(Tiny Deep Network)。而文中的VeryFast cascade或者也叫SoftCascade,则被推荐使用Benenson团队做的Doppia开源代码库。但是,这个库的环境搭建比较繁琐,折腾了我一个多星期,相当耗时。本文为此做了一些总结,方便以后再重新搭建这个环境的时候,大家能少走点弯路。

准备工作

1.安装Linux系统,本文只介绍Ubuntu16.04LTS下的环境搭建。因此我不在这里详述Linux系统的安装方法,有需求的朋友可以问问度娘经验。
2.编译环境需要用gcc-4.5以上的,而且最好把C++和CUDA也安装好。另外,代码作者在仓库说明上建议GPU的兼容性在2.0以上,而我的GT620M刚好是2.1。因此我顺便安装好相应的编译器和驱动,具体的安装方法我在这不做说明,请看我的另一篇博客。
3.安装所有的Boost库。
4.安装Google的Protocol Buffers。
5.安装Opencv 2.4系列,3.0系列版本不支持。另外,如果考虑时间上的优化,作者强烈建议编译OpenCV的时候带上编译选项-ffast-math -funroll-loops -march=native从而指定使用CUDA,并使能SIMD指令集优化。
6.安装libSDL,libjpeg, libpng。
7.安装CMake(>=2.4.3)。

后文主要对以上的3、4、6项准备工作进行详解。至于第7项准备一般是系统自带好了,如果还真没带的话,可以考虑apt一个就行。而第5项准备工作在网上有很多资料,我习惯是用cmake-gui工具来编译Opencv,对这个有兴趣的朋友可以到网上查找相关材料。如果这俩样真搞不定的话,可以评论告诉我,我适当抽时间写个补充说明,下面开始进入主要内容。

Boost库的安装

Boost的安装其实我主要是参考这篇博客
1.下载Boost 的源码包,下载地址:

https://sourceforge.net/projects/boost/files/boost/1.58.0

如果这个源码地址过期,还可以到下面的Boost的官方网站查找

http://www.boost.org/

2.在下载boost的同时,你可以安装下面四个boost的依赖库

apt-get install mpi-default-dev libicu-dev python-dev libbz2-dev #安装mpi库#支持正则表达式的UNICODE字符集#需要python的话

3.下载得到boost1_58_0.tar.bz2后,切换到文件所在目录,终端输入下面命令解压得到boost_1_58_0

tar -jxvf boost_1_58_0.tar.bz2

4.(可选)修改user-config.jam文件。在boost/tools下用下面命令搜索user-config.jam

find . -name user-config.jam

打开user-config.jam文件,并在最后添加一行代码

using mpi ; #注意mpi后面有一个空格

值得一提的是,Message Passing Interface (MPI) 库用于分布式计算中的消息传递,可以考虑弄一下,毕竟这步花不了太多时间。

5.编译Boost库,输入下面指令

sudo ./bootstrap.sh

得到b2和bjam,在执行下面指令

sudo ./b2 -a -sHAVE_ICU=1  #-a参数,代表重新编译,-sHAVE_ICU=1代表支持Unicode/ICU

然后就可以have a cup of coffee to take a rest

6.编译完成后,输入下面命令安装boost库

sudo ./b2 install

安装libSDL

用下列指令安装libSDL库

sudo apt-get install libsdl1.2-dev

安装protobuf库

sudo apt-get install libprotobuf-dev libprotoc-dev python-protobuf protobuf-compiler

编译Doppia

STEP1:配置环境变量与编译选项

在编译各种程序之前,我首先打开并编辑common_settings.cmake文件,添上一些自己机器的配置信息,下面是我的配置信息仅作参考。

....elseif(${HOSTNAME} STREQUAL  "my-Apple-computer")# change the_name_of_your_machine to what /bin/hostname returns message(STATUS "Using my-Apple-computer compilation options")# start with an empty section, and see what fails as you go through the re    adme.text instructionsset(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORCE_INLINES")set(opencv_INCLUDE_DIRS "/usr/local/opencv2/include")set(opencv_LIBRARY_DIRS "/usr/local/opencv2/lib")option(USE_GPU "Should the GPU be used ?" TRUE)set(CUDA_BUILD_CUBIN OFF)set(local_CUDA_LIB_DIR "/usr/local/cuda/lib64")set(cuda_LIBS "")set(Boost_DIR "/usr/local")set(Boost_LIBRARY_DIRS "/usr/local/lib")set(Boost_INCLUDE_DIRS "/usr/local/include/boost")set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT=1")

然后,运行脚本./generate_protocol_buffer_files.sh,输出以下信息

+ echo Generating objects detection files...Generating objects detection files...+ cd src/objects_detection/+ protoc --cpp_out=./ detector_model.proto detections.proto[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: detector_model.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: detections.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)+ protoc --python_out=../../tools/objects_detection/ detector_model.proto detections.proto[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: detector_model.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: detections.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)+ cd ../..+ cd src/stereo_matching/ground_plane/+ protoc --cpp_out=./ plane3d.proto[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: plane3d.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)+ protoc --python_out=../../../tools/stixels_evaluation plane3d.proto[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: plane3d.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)+ cd ../../..+ cd src/stereo_matching/stixels/+ protoc --cpp_out=./ -I. -I../ground_plane --include_imports stixels.proto ground_top_and_bottom.proto--include_imports only makes sense when combined with --descriptor_set_out.[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: stixels.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: ground_top_and_bottom.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: plane3d.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)+ protoc --python_out=../../../tools/stixels_evaluation -I. -I../ground_plane --include_imports stixels.proto ground_top_and_bottom.proto--include_imports only makes sense when combined with --descriptor_set_out.[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: stixels.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: ground_top_and_bottom.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: plane3d.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)+ cd ../../..+ cd src/video_input/calibration+ protoc --cpp_out=./ calibration.proto[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: calibration.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)+ cd ../../..+ cd src/helpers/data+ protoc --cpp_out=./ DataSequenceHeader.proto[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: DataSequenceHeader.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)+ protoc --python_out=../../../tools/data_sequence DataSequenceHeader.proto[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: DataSequenceHeader.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)+ cd ../../..+ cd src/helpers+ cd ../..+ cd src/tests/data_sequence/+ protoc --cpp_out=./ TestData.proto[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: TestData.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)+ cd ../../..+ echo End of game. Have a nice day!End of game. Have a nice day!

STEP2:编译CPU单跑代码

根据官方教程,我们首先编译
doppia/src/applications/ground_estimation
这是一个能够保证咱们cmake和c++编译没问题的简单验证程序。
1.对于不同程序编译我们需要进入不同的目录下:

cd doppia/src/applications/ground_estimation

2.运行cmake -D CMAKE_BUILD_TYPE=RelWithDebInfo . && make
如果你确定这次编译一定成功,而且你的机器有足够内存,你可以考虑使用cmake . && make -j5来加速编译。
3.对于已经编译成功过的程序,可以直接执行下面的指令。

cmake . && make -j2 && ./ground_estimation -c test.config.ini

如果ground_estimation编译成功以后,我们就可以开始编译ground_estimation

$ cd doppia/src/applications/stixel_world$ cmake . && make -j2 && OMP_NUM_THREADS=4 ./stixel_world -c fast.config.ini --gui.disable false$ cmake . && make -j2 && OMP_NUM_THREADS=4 ./stixel_world -c fast_uv.config.ini --gui.disable false

STEP3:编译测试代码

1.$ cd doppia/src/applications/objects_detection
2.cmake -D CMAKE_BUILD_TYPE=RelWithDebInfo . && make -j2
3.运行代码

$ cmake . && make -j2 && OMP_NUM_THREADS=4 ./objects_detection -c cvpr2012_very_fast_over_bahnhof.config.ini --gui.disable false

其实STEP1编过之后,下来的问题都不是很大了,如果来到这一步STEP3也很成功的话,就说明你这个环境配置已经没太大问题了。所以,后面根据作者在的编译说明继续执行step4和step5就好了。

总结

长话短说,这个配置成功与否在于准备工作的boost与protobuf库的安装。另外,最重要的是comom_settings.cmake的配置,这个配置文件编辑如果好了,基本上后面是事半功倍的。

(FIN)

0 0
原创粉丝点击