Ubuntu14.04下配置测试Faster R-CNN+Caffe(Matlab+CPU)目标检测
Faster R-CNN是当前目标检测领域内性能最好的算法之一,它将RPN(Region Proposal Network)网络和Fast R-CNN网络结合到了一起,实现了一个端到端的目标检测框架。作者Shaoqing Ren在github上公开了源代码,可以很方便地在自己的机器上进行测试。本文记录的是Ubuntu14.04下配置和测试Faster R-CNN的过程,其中包括Caffe的安装和编译过程,针对的是Matlab和仅使用CPU的环境。 文章arXiv链接: 下载源代码Matlab源码链接: Python实现源码: 下载源码faster_rcnn-master.zip以及其中的caffe源码,解压至本地目录。 安装编译Caffe1.安装依赖项[1] 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-devBLAS: sudo apt-get install libatlas-base-devPython用户需安装,Matlab不需要: sudo apt-get install the python-devGPU运行环境还需安装CUDA,使用CPU无需安装。 Ubuntu14.04依赖项: sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-devUbuntu12.04版本较低,需要手动安装依赖项: # glog wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz tar zxvf glog-0.3.3.tar.gz cd glog-0.3.3 ./configure make && make install # gflags wget https://github.com/schuhschuh/gflags/archive/master.zip unzip master.zip cd gflags-master mkdir build && cd build export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1 make && make install # lmdb git clone https://github.com/LMDB/lmdb cd lmdb/libraries/liblmdb make && make install 2.编译
修改完成后,执行如下命令: cp Makefile.config.example Makefile.config make clean make all make test make runtest采用并行的方式可以更快地完成编译过程,只需使用`make all -j8`命令。其中数字8表示并行线程的数目,建议将该线程数目修改为机器的内核数。 为了能够在Matlab中正常使用,还需执行以下命令: make matcaffe 之后在 3.测试示例[2] 在正式测试前,需要下载训练好的caffemodel文件[3]。有两种方式,直接在浏览器里输入地址下载,也可以运行脚本文件下载。我选择直接用浏览器下载,下载地址如下: 该模型文件243.9M,下载完成后将其拷贝到caffe根目录下的 接着启动Matlab,切换到caffe的根目录,将caffe_.mex64的路径添加进来,便于加载。 addpath('./matlab/+caffe/private');切换到`matlab/demo/`目录下,执行如下命令来测试示例: I = imread('../../examples/images/cat.jpg'); [scores,maxlabel] = classification_demo(I,0);需要特别注意,classification_demo(I,0)函数中的0表示使用CPU,如果改为1则表示GPU。执行成功后,将会返回如下信息: Elapsed time is 0.025054 seconds. Elapsed time is 1.069503 seconds. Cleared 0 solvers and 1 stand-alone nets其中maxlabel=282,表示具有最大分类概率的是第282个类别。输入`figure;plot(scores);`显示所有类别上的分类概率,如下图所示。 从图中可以看出,该图片被分到第282类的概率最高。至此,程序测试完成,说明Caffe安装配置成功。 配置运行Faster R-CNNFaster R-CNN的配置和运行十分简单,启动Matlab,切换到faster_rcnn目录下。运行faster_rcnn_build.m,在仅使用CPU的情况下,Compiling nms_gpu_mex时会出错[4]。但是其他能够编译成功,这里不用担心。 run faster_rcnn_build.m run startup.m 获取训练好的模型,可以通过执行文件下载: run fetch_data/fetch_faster_rcnn_final_model.m 个人建议直接通过作者github主页上的链接来下载模型,地址在主页最后一行给出,选择其一下载。
模型较大,下载完成后直接将其解压至faster_rcnn根目录下。 在experiments目录下有测试文件,因为只使用CPU,运行前需要将其设置为不使用GPU。
文件中的第3、4行需要注释掉,第9行的opts.use_gpu改为false。以下是修改后的代码, %% -------------------- CONFIG -------------------- opts.caffe_version = 'caffe_faster_rcnn'; % opts.gpu_id = auto_select_gpu; % active_caffe_mex(opts.gpu_id,opts.caffe_version); opts.per_nms_topN = 6000; opts.nms_overlap_thres = 0.7; opts.after_nms_topN = 300; opts.use_gpu = false; opts.test_scales = 600; 此外,由于VGG16模型较大,运行过程中会崩溃,因此将模型改为ZF,修改后如下: % model_dir = fullfile(pwd,'output','faster_rcnn_final','faster_rcnn_VOC0712_vgg_16layers'); %% VGG-16 model_dir = fullfile(pwd,'output','faster_rcnn_final','faster_rcnn_VOC0712_ZF'); %% ZF 至此,修改完毕。执行该程序,能够正常运行说明测试成功。我的处理器是Intel Core i7-2600 CPU @ 3.40GHz × 8 ,输出如下信息: 001763.jpg (500x375): time 3.258s (resize+conv+proposal: 2.452s,nms+regionwise: 0.806s) 004545.jpg (500x375): time 4.073s (resize+conv+proposal: 2.543s,nms+regionwise: 1.530s) 000542.jpg (500x375): time 3.064s (resize+conv+proposal: 2.526s,nms+regionwise: 0.538s) 000456.jpg (500x375): time 3.757s (resize+conv+proposal: 2.497s,nms+regionwise: 1.259s) 001150.jpg (500x375): time 3.400s (resize+conv+proposal: 2.481s,nms+regionwise: 0.919s) mean time: 3.510s Cleared 0 solvers and 2 stand-alone nets 参考文献: (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- Ubuntu下编译vlc for android
- Ubuntu 16.04 安装后鼠标键盘无反应问题
- Ubuntu16.04下搭建开发环境及编译tiny4412 Android系统
- Ubuntu16.04.1 安装Nginx
- Ubuntu14.04 LTS 安装Doris、StaMPS、ROI_PAC
- ubuntu sudo update与upgrade的作用及区别
- Ubuntu 16.04 一系列软件安装命令,包括QQ、搜狗、Chrome、
- Ubuntu如何新增管理员账户?
- Ubuntu系统上集群之间ssh实现无密码登录
- gnome-terminal – 升级到Ubuntu 15.04后无法重命名gnome终