The value of knowledge lies not in possession, but in share.

0%

Faster-RCNN的搭建和测试

下载Faster-RCNN

1
2
cd ~
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

安装Python依赖包

1
2
3
4
sudo apt-get install python-pip
sudo pip install cython
sudo apt-get install python-opencv
sudo pip install easydic

生成Cython模块

1
2
cd ~/py-faster-rcnn/lib/
make

安装Atlas

1
sudo apt-get install libatlas-base-dev

生成Caffe和pycaffe

1
2
cd ~/py-faster-rcnn/caffe-fast-rcnn
cp Makefile.config.example Makefile.config

编辑Makefile.config,根据自己的需要修改相应模式,其中重点关注CPU_ONLY 和WITH_PYTHON_LAYER以及CUDNN等处,若是在CPU的情况下,请务必修改为CPU_ONLY := 1

编译环境

1
2
3
4
5
6
7
8
cd ~/py-faster-rcnn/caffe-fast-rcnn
mkdir build
cd build
cmake ..
make all -j16("‐j16"是使用 CPU 的多核进行编译,可以极大地加速编译的速度)
make install
make runtest -j16(如果出错没有关系,直接进行下一步)
make pycaffe(编译pycaffe)

下载fetch_fast_rcnn_models

下载网址:(链接:http://pan.baidu.com/s/1pJVburD 密码:11m0)

将下载好的faster_rcnn_models.tgz放到/py-faster-rcnn/data这个目录下,右键提取到此处,即是解压。

CPU环境下所需要的操作

  • 1
    vim ~/py-faster-rcnn/lib/fast_rcnn/config.py

    将 __C.USE_GPU_NMS = False

  • 1
    vim ~/py-faster-rcnn/tools/test_net.py

    注释掉:caffe.set_mode_gpu() ,其下方添加: caffe.set_mode_cpu()

  • 1
    vim ~/py-faster-rcnn/tools/train_net.py

    注释掉:caffe.set_mode_gpu() ,其下方添加: caffe.set_mode_cpu()

  • 1
    vim ~/py-faster-rcnn/lib/setup.py

    注释掉GPU相关代码,如下

    1
    #CUDA = locate_cuda()
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    #    Extension('nms.gpu_nms',
    # ['nms/nms_kernel.cu', 'nms/gpu_nms.pyx'],
    # library_dirs=[CUDA['lib64']],
    # libraries=['cudart'],
    # language='c++',
    # runtime_library_dirs=[CUDA['lib64']],
    # # this syntax is specific to this build system
    # # we're only going to use certain compiler args with nvcc and not with
    # # gcc the implementation of this trick is in customize_compiler() below
    # extra_compile_args={'gcc': ["-Wno-unused-function"],
    # 'nvcc': ['-arch=sm_35',
    # '--ptxas-options=-v',
    # '-c',
    # '--compiler-options',
    # "'-fPIC'"]},
    # include_dirs = [numpy_include, CUDA['include']]
    # ),
  • 1
    vim ~/py-faster-rcnn/lib/fast_rcnn/nms_wrapper.py

    注释掉 #from nms.gpu_nms import gpu_nms

运行Demo

1
2
3
4
cd ~/py-faster-rcnn/tools
./demo.py 或python demo.py
#当此处报错时请尝试python2 demo.py
#CPU环境下运行话:python2 demo.py --cpu

若提示缺少某个模块(module),网上搜索下,安装给出的教程安装相应模块,建议尽量终端中命令安装.

效果图如下(仅贴了一张图):

🍭支持一根棒棒糖吧!