cuda8+cuDNN Faster R-CNN安装塈运行demo

安装cuda

cuda8安装参见网上教程

安装cuDNN

py-faster-rcnn/caffe-fast-rcnn目前不支持cuDNN5。 如果使用cuDNN5,在编译caffe-fast-rcnn时会报错:

error: argument of type “int” is incompatible with parameter of type “cudnnNanPropagation_t” 解决编译错误的方法参见我的另一篇博客: 《使用cuDNN5编译py-faster-rcnn错误:cudnn.hpp(126): error: argument of type “int” is incompatible …》

如果使用cuDNN4就不会有编译错误。 cuDNN安装方式(cuDNN4为例)

tar zxvf cudnn-7.0-linux-x64-v4.0-prod.tgz 
sudo cp cuda/include/cudnn.h /usr/local/cuda/include 
sudo cp -d cuda/lib64/libcudnn* /usr/local/cuda/lib64 

cuDNN4 OR 5?

那么应该安装cuDNN4还是cuDNN5呢? 这取决于你的NVIDIA显卡与cuDNN之间是否有兼容性问题。 如果你的电脑上用cuDNN4能正常执行demo,那自然好, 如果不能,就换cuDNN5试试,原因参见我的另一篇博客 《cuDNN兼容性问题造成的caffe/mnist,py-faster-rcnn/demo运行结果错误》

下载faster r-cnn代码

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

下载模型数据

模型数据有点大,要花点时间

$./data/scripts/fetch_faster_rcnn_models.sh

编译caffe

这里的caffe是Faster R-CNN自带的caffe,在caffe-fast-rcnn文件夹下

$cd caffe-fast-rcnn
#如果没有cmake,要安装cmake
#$sudo apt-get install cmake
# 执行cmake生成Makefile
#编译CPU版本
#cmake -DCPU_ONLY=ON -DBLAS=Open .
#编译GPU版本
$cmake -DBLAS=Open -DCUDA_NVCC_FLAGS=--Wno-deprecated-gpu-targets .
$make -j 8

关于编译caffe的细节参见我的另一篇博客 《Ubuntu16:cmake生成Makefile编译caffe过程(OpenBLAS/CPU+GPU)塈解决nvcc warning:The ‘compute_20’, ‘sm_20’》

安装pycaffe的依赖库

caffe-fast-rcnn/python/requirement.txt文件列出了pycaffe的所有依赖库,要把requirements下的依赖都装一遍

guyadong@10km-ubuntu:~/tmp/py-faster-rcnn/caffe-fast-rcnn/python$ cat requirements.txt Cython>=0.19.2 numpy>=1.7.1 scipy>=0.13.2 scikit-image>=0.9.3 matplotlib>=1.3.1 ipython>=3.0.0 h5py>=2.2.0 leveldb>=0.191 networkx>=1.8.1 nose>=1.3.0 pandas>=0.12.0 python-dateutil>=1.4,<2 protobuf>=2.5.0 python-gflags>=2.0 pyyaml>=3.10 Pillow>=2.3.0

pycaffe的依赖库是用Python的包管理工具pip来安装的,如果还没安装pip,则要先安装python-pip

$ sudo apt-get install python-pip
$ sudo apt-get install python-opencv
$ sudp apt-get install python-tk
$ sudo apt-get install python-dateutil
$ cd caffe-fast-rcnn/python
$ for req in $(cat requirements.txt); do sudo pip install $req; done
$ sudo pip install easydict

编译faster-rcnn

编译好caffe-fast-rcnn后,在py-faster-rcnn/lib中执行make命令:

$ make running build running build_ext skipping ‘utils/bbox.c’ Cython extension (up-to-date) building ‘utils.cython_bbox’ extension creating build creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/utils x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c utils/bbox.c -o build/temp.linux-x86_64-2.7/utils/bbox.o -Wno-cpp -Wno-unused-function creating build/lib.linux-x86_64-2.7 creating build/lib.linux-x86_64-2.7/utils x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/utils/bbox.o -o build/lib.linux-x86_64-2.7/utils/cython_bbox.so skipping ‘nms/cpu_nms.c’ Cython extension (up-to-date) building ‘nms.cpu_nms’ extension creating build/temp.linux-x86_64-2.7/nms x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c nms/cpu_nms.c -o build/temp.linux-x86_64-2.7/nms/cpu_nms.o -Wno-cpp -Wno-unused-function creating build/lib.linux-x86_64-2.7/nms x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/nms/cpu_nms.o -o build/lib.linux-x86_64-2.7/nms/cpu_nms.so skipping ‘nms/gpu_nms.cpp’ Cython extension (up-to-date) building ‘nms.gpu_nms’ extension /usr/local/cuda-8.0/bin/nvcc -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/local/cuda-8.0/include -I/usr/include/python2.7 -c nms/nms_kernel.cu -o build/temp.linux-x86_64-2.7/nms/nms_kernel.o -arch=sm_35 –ptxas-options=-v -c –compiler-options ‘-fPIC’ ptxas info : 0 bytes gmem ptxas info : Compiling entry function ‘_Z10nms_kernelifPKfPy’ for ‘sm_35’ ptxas info : Function properties for _Z10nms_kernelifPKfPy 0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads ptxas info : Used 25 registers, 1280 bytes smem, 344 bytes cmem[0], 8 bytes cmem2 x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/local/cuda-8.0/include -I/usr/include/python2.7 -c nms/gpu_nms.cpp -o build/temp.linux-x86_64-2.7/nms/gpu_nms.o -Wno-unused-function cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1777:0, from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:18, from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:4, from nms/gpu_nms.cpp:449: /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning “Using deprecated NumPy API, disable it by ” “#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION” [-Wcpp] #warning “Using deprecated NumPy API, disable it by ” \ ^ c++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/nms/nms_kernel.o build/temp.linux-x86_64-2.7/nms/gpu_nms.o -L/usr/local/cuda-8.0/lib64 -Wl,-R/usr/local/cuda-8.0/lib64 -lcudart -o build/lib.linux-x86_64-2.7/nms/gpu_nms.so skipping ‘pycocotools/_mask.c’ Cython extension (up-to-date) building ‘pycocotools._mask’ extension creating build/temp.linux-x86_64-2.7/pycocotools x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -Ipycocotools -I/usr/include/python2.7 -c pycocotools/maskApi.c -o build/temp.linux-x86_64-2.7/pycocotools/maskApi.o -Wno-cpp -Wno-unused-function -std=c99 x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -Ipycocotools -I/usr/include/python2.7 -c pycocotools/_mask.c -o build/temp.linux-x86_64-2.7/pycocotools/_mask.o -Wno-cpp -Wno-unused-function -std=c99 creating build/lib.linux-x86_64-2.7/pycocotools x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/pycocotools/maskApi.o build/temp.linux-x86_64-2.7/pycocotools/_mask.o -o build/lib.linux-x86_64-2.7/pycocotools/_mask.so

运行demo

$python tools/demo.py 

…. I0314 16:11:46.644143 22175 net.cpp:270] This network produces output bbox_pred I0314 16:11:46.644161 22175 net.cpp:270] This network produces output cls_prob I0314 16:11:46.644192 22175 net.cpp:283] Network initialization done. [libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] Reading dangerously large protocol message. >If the message turns out to be larger than 2147483647 bytes, parsing will be halted for security reasons. To >increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in >google/protobuf/io/coded_stream.h. [libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 548317115 I0314 16:11:46.803853 22175 net.cpp:816] Ignoring source layer data I0314 16:11:46.873862 22175 net.cpp:816] Ignoring source layer drop6 I0314 16:11:46.883658 22175 net.cpp:816] Ignoring source layer drop7 I0314 16:11:46.883672 22175 net.cpp:816] Ignoring source layer fc7_drop7_0_split I0314 16:11:46.883926 22175 net.cpp:816] Ignoring source layer loss_cls I0314 16:11:46.883936 22175 net.cpp:816] Ignoring source layer loss_bbox I0314 16:11:46.885593 22175 net.cpp:816] Ignoring source layer silence_rpn_cls_score I0314 16:11:46.885612 22175 net.cpp:816] Ignoring source layer silence_rpn_bbox_pred Loaded network /home/guyadong/tmp/py-faster-rcnn/data/faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Demo for data/demo/000456.jpg Detection took 2.097s for 300 object proposals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Demo for data/demo/000542.jpg Detection took 1.695s for 161 object proposals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Demo for data/demo/001150.jpg Detection took 1.908s for 194 object proposals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Demo for data/demo/001763.jpg Detection took 1.785s for 196 object proposals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Demo for data/demo/004545.jpg Detection took 1.881s for 300 object proposals

如果在CPU上运行,要复杂一些,需要手工修改一些脚本,参见《Faster R-CNN CPU环境搭建》.

参考资料

《Faster R-CNN CPU环境搭建》 《Faster R-CNN安装笔记,只用CPU 》

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Ken的杂谈

博客从ASP.NET 迁移到了ASP.NET Core 2.0

在迁移之前,本站点是基于 ASP.NET MVC 4构建且部署在Linux+Mono环境下,Web服务器使用的是Jexus,在 .NET Core出来之前,这是...

943
来自专栏c#开发者

解决:TF30170: Microsoft.ProjectCreationWizard.WorkItemTracking

Error TF30170: The plugin Microsoft.ProjectCreationWizard.WorkItemTracking fail...

3607
来自专栏张善友的专栏

在 CentOS 上使用 Jexus 托管运行 ZKEACMS

ZKEACMS Core 是基于 .net core 开发的,可以在 windows, linux, mac 上跨平台运行,接下来我们来看看如何在 CentOS...

6430
来自专栏运维前线

Docker 学习资源整理

Awesome Docker A curated list of Docker resources and projects Inspired by...

4235
来自专栏张善友的专栏

.NET Framework 4.5.2 静默安装参数

Microsoft .NET Framework 4.5.2 是针对 Microsoft .NET Framework 4、Microsoft .NET Fra...

2368
来自专栏张善友的专栏

SQL Server 2005 x64: Required 64-bit ASP.Net

在64位的Windows Server 2008 R2上安装 Microsoft SQL Server 2005 x64 ,得到下面的警告,如果不需要安装Rep...

19110
来自专栏张善友的专栏

ASP.NET MVC 2 转换工具

似水流年报告了ASP.NET MVC 2 正式发布,那么我们有许多ASP.NET MVC 1.0的程序需要移植到2.0怎么办呢?Eilon Lipton 已经发...

1689
来自专栏张善友的专栏

Mono 4.0 Mac上运行asp.net mvc 5.2.3

Mono 4.0 已经发布,二进制包已经准备好,具体的发布说明参见:http://www.mono-project.com/docs/about-mono/re...

1875
来自专栏张善友的专栏

Windows Server 2008 与 .NET Framework 的版本之间有什么关系

Windows Server 2008就要上市了,用虚拟机安装了两个版本的,一个Server Core的,也就是类Unix的命令行管理的版本,另一个是企业板。I...

24110
来自专栏菩提树下的杨过

asp.net mvc中的路径选择

MVC的路径选择十分灵活,可以用类似/parm1/parm2/parm3/ 的方式(这个有点象iis的urlrewriter),也可以象传统url那样用/?pa...

1938

扫码关注云+社区