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 条评论
登录 后参与评论

相关文章

来自专栏散尽浮华

kvm虚拟化管理平台WebVirtMgr部署-虚拟化环境安装-完整记录(0)

打算部署kvm虚拟机环境,下面是虚拟化部署前的一些准备工作: 操作系统环境安装 1)修改内核模式为兼容内核启动 [root@ops ~]# uname -a L...

1867
来自专栏人工智能LeadAI

配置深度学习主机与环境(TensorFlow+1080Ti) | 第三章 CUDA与CUDNN安装

01 概念介绍 CUDA(Compute Unified Device Architecture 统一计算设备架构) CUDA(Compute Unified ...

3917
来自专栏机器之心

这是一份你们需要的Windows版深度学习软件安装指南

选自Github 机器之心编译 参与:蒋思源、刘晓坤 本文从最基本的依赖项开始,依次配置了 VS 2015、Anaconda 4.4.0、CUDA 8.0.61...

3698
来自专栏用户2442861的专栏

在Ubuntu 14.04上安装Caffe

844
来自专栏简书专栏

Windows系统查看CUDA版本号

在按住Win键的情况下,按P键,呼唤出搜索框。 在搜索框中输入control panel,如下图所示:

602
来自专栏计算机视觉战队

每日一学——TensorFlow的学习

什么是TensorFlow? TensorFlow 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库。节点(Nodes)在图中表...

3388
来自专栏乐沙弥的世界

MySQL MHA 典型使用场景

Since MHA Manager uses very little CPU/Memory resources, you can manage lots of ...

640
来自专栏bboysoul

统计你的VPS流量(vnstat)

虽然自己的服务器平时没什么事情,也没什么人用,但是我还是很在意自己的流量的,所以就使用了vnstat来监控自己的服务器流量

932
来自专栏贾志刚-OpenCV学堂

Windows下TensorFlow安装与代码测试

Windows下TensorFlow安装与代码测试 一:Tensorflow介绍 TensorFlow是谷歌的深度学习应用开发框架,其思想基于数据流图与节点图实...

3968
来自专栏陈林峰的专栏

闲置资源再利用:个人电脑上畅玩 TensorFlow

眼下 github 社区最火的开源项目莫过于 tensorflow (后简称TF),本文介绍一种基于windows平台下搭建 TF 运行和开发环境,带大家畅玩 ...

6400

扫码关注云+社区