TX1上faster-Rcnn编译测试与问题解决

部分借鉴http://blog.csdn.net/u011635764/article/details/52831167


根据之前发的文章,之前在TX1上已经安装好caffe了 

基本环境是,Ubuntu16.04系统,cuda8.0, cudnn, opencv3.1.0等caffe必需的依赖

首先安装pip用于安装之后的Python依赖

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip

安装Python依赖包

sudo pip install Cython
sudo pip install easydict

从github上下载程序源码

git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git


修改并编译Cython,打开py-faster-rcnn/lib找到setup.py

根据自己的显卡计算能力修改第135行,查询网址为:https://developer.nvidia.com/cuda-gpus

TX1上faster-Rcnn编译测试与问题解决_第1张图片

TX1计算能力为5.3,则修改为

'nvcc': ['-arch=sm_53',

之后执行make进行编译


之后打开caffe-faster-rcnn将安装好的的caffe目录下的Makefile.config和Makefile.config.example复制到该目录下

然后对Makefile.config文件进行修改

USE_CUDNN := 1
OPENCV_VERSION := 3
CUSTOM_CXX := g++
WITH_PYTHON_LAYER := 1
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/lib/x86_64-Linux-gnu/hdf5/serial /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
USE_PKG_CONFIG := 1

以上是在网上查阅各种资料汇总而得,可能有多余的修改,但是能顺利跑通

因为作者的caffe版本不支持新的cudnn加速,我们需要将

py-faster-rcnn/caffe-fast-rcnn/include/caffe/util/cudnn.hpp  
py-faster-rcnn/caffe-fast-rcnn/src/caffe/util/cudnn.cpp
py-faster-rcnn/caffe-fast-rcnn/src/caffe/layers/ 目录下16个cudnn_开头的文件
py-faster-rcnn/caffe-fast-rcnn/include/caffe/layers/目录下8个cudnn_开头的文件

用已安装好的caffe相应目录下的对应文件进行替换

修改一个include错误,打开

py-faster-rcnn/caffe-fast-rcnn/src/caffe/test/test_smooth_L1_loss_layer.cpp

删除第十一行
#include "caffe/vision_layers.hpp"

下面终于开始caffe编译了,此处出现一个大坑

如果直接通过网上很多教程说的方法直接用make编译,会报错如下

AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5
collect2: error: ld returned 1 exit status
Makefile:554: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

此处必须通过cmake进行编译

caffe-fast-rcnn路径下,在终端执行

make clean
mkdir build
cd build
cmake ..
make all -j4

就能通过编译,原因貌似是make只能在当前目录下寻找动态链接库,具体原因还希望有大神进行解答
之后在caffe-fast-rcnn路径下编译

sudo make -j8 test

立刻完成

之后在caffe-fast-rcnn路径下执行

make runtest 

发现问题

F0511 14:58:00.916214  7960 db_lmdb.hpp:14] Check failed: mdb_status == 0 (12 vs. 0) Cannot allocate memory
*** Check failure stack trace: ***
    @       0x7f8401e718  google::LogMessage::Fail()
    @       0x7f84020614  google::LogMessage::SendToLog()
    @       0x7f8401e290  google::LogMessage::Flush()
    @       0x7f84020eb4  google::LogMessageFatal::~LogMessageFatal()
    @       0x7f843b37ec  caffe::db::LMDB::Open()
    @           0x93b264  caffe::DBTest<>::SetUp()
    @           0xcb8f04  testing::internal::HandleExceptionsInMethodIfSupported<>()
    @           0xcb1dd8  testing::Test::Run()
    @           0xcb1f98  testing::TestInfo::Run()
    @           0xcb20a4  testing::TestCase::Run()
    @           0xcb3b08  testing::internal::UnitTestImpl::RunAllTests()
    @           0xcb3e1c  testing::UnitTest::Run()
    @           0x84f570  main
    @       0x7f7fc008a0  __libc_start_main
Aborted
src/caffe/test/CMakeFiles/runtest.dir/build.make:57: recipe for target 'src/caffe/test/CMakeFiles/runtest' failed
make[3]: *** [src/caffe/test/CMakeFiles/runtest] Error 134
CMakeFiles/Makefile2:328: recipe for target 'src/caffe/test/CMakeFiles/runtest.dir/all' failed
make[2]: *** [src/caffe/test/CMakeFiles/runtest.dir/all] Error 2
CMakeFiles/Makefile2:335: recipe for target 'src/caffe/test/CMakeFiles/runtest.dir/rule' failed
make[1]: *** [src/caffe/test/CMakeFiles/runtest.dir/rule] Error 2
Makefile:240: recipe for target 'runtest' failed
make: *** [runtest] Error 2

此处是因为分配内存不够,解决方法为:

cd examples/mnist

convert_mnist_data.cpp中

CHECK_EQ(mdb_env_set_mapsize(mdb_env, 1099511627776), MDB_SUCCESS) // 1TB 

修改为

CHECK_EQ(mdb_env_set_mapsize(mdb_env, 1073741824), MDB_SUCCESS) // 1GB

同样的,在/src/caffe/util/db_lmdb.cpp中
将LMDB_MAP_SIZE修改为4294967296
之后在caffe-fast-rcnn路径下执行

sudo make pycaffe

就可以完成编译

之后下载已经训练好的模型,网上大多数方法为

./data/scripts/fetch_faster_rcnn_models.sh

我发现网站无响应,大家可以直接用浏览器打开https://dl.dropboxusercontent.com/s/o6ii098bu51d139/faster_rcnn_models.tgz进行下载

下载完成后,解压文件夹至py-faster-rcnn\data目录下

最后,执行demo程序

python /tools/demo.py

发现报错

ImportError: No module named skimage.io

解决方法为,执行

sudo apt-get install python-skimage

再次执行demo又出现问题

ImportError: No module named google.protobuf.internal

解决方法为,执行

sudo pip install protobuf

呼,这样就可以执行demo了,希望这篇文章能帮助到大家

但是,执行demo时又出现了问题,由于这是在嵌入式环境下进行,默认载入的模型是VGG16网络,VGG16网络比较大,可能会出现内存不足,导致killed

Loaded network /mnt/sd1/faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/000456.jpg
Detection took 1.879s for 300 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/000542.jpg
Killed

解决方法是打开tools/demo.py文件将

parser.add_argument('--net', dest='demo_net', help='Network to use [vgg16]',
                        choices=NETS.keys(), default='vgg16')

修改为

parser.add_argument('--net', dest='demo_net', help='Network to use [zf]',
                        choices=NETS.keys(), default='zf')

即可跑通demo

Loaded network /mnt/sd1/faster_rcnn_models/ZF_faster_rcnn_final.caffemodel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/000456.jpg
Detection took 0.510s for 300 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/000542.jpg
Detection took 0.552s for 135 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/001150.jpg
Detection took 1.014s for 231 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/001763.jpg
Detection took 0.714s for 200 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/004545.jpg
Detection took 0.577s for 300 object proposals

上文可以看到,faster-Rcnn在TX1运行比较快,但跟PC端还是有相当大差距的,得到的结果是









你可能感兴趣的:(TX1,深度学习,Faster-RCNN,TX1,caffe,框架,faster-Rcnn)