当前位置: 代码迷 >> 综合 >> Faster R-CNN CPU环境搭建
  详细解决方案

Faster R-CNN CPU环境搭建

热度:14   发布时间:2023-12-05 21:52:14.0

参考:https://blog.csdn.net/zyb19931130/article/details/53842791

             https://blog.csdn.net/Lin_xiaoyi/article/details/78183683?locationNum=5&fps=1

             https://blog.csdn.net/m0_37717568/article/details/70743175

配置,编译与安装环境:

$ pip install cython
$ pip install easydict
$ sudo apt-get install python-opencv

1.下载fasrer-rcnn源代码并安装:

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

2.编译cython模块 

cd /py-faster-rcnn/lib
修改setup.py文件,注释掉GPU相关代码,如下:
#CUDA = locate_cuda()
#self.set_executable('compiler_so', CUDA['nvcc'])
# 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']]
#),setup.py修改完成后,执行make

在py-faster-rcnn/lib目录下,运行以下命令:make

3、编译caffe和pycaffe

到/py-faster-rcnn/caffe-fast-rcnn/目录下,复制Makefile.config.example为Makefile.config,并修改Makefile.config文件和CMakeLists.txt文件(OFF改成ON),修改如下:

    去掉注释CPU_ONLY :=1  注释掉CUDA有关的行:  #CUDA_DIR := /usr/local/cuda  #CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \  #        -gencode arch=compute_20,code=sm_21 \  #        -gencode arch=compute_30,code=sm_30 \  #        -gencode arch=compute_35,code=sm_35 \  #        -gencode arch=compute_50,code=sm_50 \  #        -gencode arch=compute_50,code=compute_50  去掉注释WITH_PYTHON_LAYER := 1  INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial  LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/i386-linux-gnu/hdf5/serial /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial  #TEST_GPUID := 0  
    caffe_option(CPU_ONLY  "Build Caffe without CUDA support" ON) # TODO: rename to USE_CUDA  

编译:

    cd ~/py-faster-rcnn/caffe-fast-rcnn  make -j8&& make pycaffe  

4. 完成之后修改一些文件,因为默认为GPU模式

A>将 ~/py-faster-rcnn/lib/fast_rcnn/config.py的如下内容:  __C.USE_GPU_NMS = False

B>将 ~/py-faster-rcnn/tools/test_net.py和 ~/py-faster-rcnn/tools/train_net.py的caffe.set_mode_gpu()修改为caffe.set_mode_cpu().

C:修改/py-faster-rcnn/lib/fast_rcnn/nms_wrapper.py文件(注释该引用,并将False改成True)
#from nms.gpu_nms import gpu_nms

def nms(dets, thresh, force_cpu=True):

5.在环境一切就绪的情况下,将faster的模型下载下来(模型存放在data里):

cd py-fast-rcnn
./data/script/fetch_faster_rcnn_models.sh 
6. 在/home/xxx/py-faster-rcnn/tools目录下运行, python demo.py --cpu或者./tools/demo.py --cpu 

遇到的问题:

src/caffe/test/test_smooth_L1_loss_layer.cpp:11:35: fatal error: caffe/vision_layers.hpp

解决方法:
找到文件$CAFFE_ROOT/src/caffe/test/test_smooth_L1_loss_layer.cpp
注释或删除第十一行

11 #include "caffe/vision_layers.hpp"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

此外:

1:进一步想用VOC2007进行实验,给出数据下载方式

(1)下载训练、测试数据集

wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar

wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar

wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCdevkit_08-Jun-2007.tar

 (2)解压

tar xvf VOCtrainval_06-Nov-2007.tar

tar xvf VOCtest_06-Nov-2007.tar

tar xvf VOCdevkit_08-Jun-2007.tar

 

(3)为了PASCAL VOC创建symlinks,创建软连接

ln -s VOCdevkit VOCdevkit2007

2:想安装opencv ,下载opencv-3.0.0.zip

 安装包存在了百度云网盘。链接:http://pan.baidu.com/s/1jHCpwpg 密码:m2je。

3 : 单独下载faster_rcnn模型,链接: https://pan.baidu.com/s/1miDWCEc 密码: xq4y

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

注:py-faster-rcnn在测试模型的时候,可以选择使用cpu mode或者gpu mode,但是如果使用该框架训练自己的模型,就只能使用gpu了。应该是作者考虑训练速度的原因,对roi_pooling_layer和smooth_L1_loss_layer只使用和提供了gpu版本的代码.

参考:https://blog.csdn.net/qq_14975217/article/details/51495844

  相关解决方案