Mac下跑仅CPU模式下的py-faster-rcnn

来源:互联网 发布:php用ajaxs上传图片 编辑:程序博客网 时间:2024/06/06 21:00

该篇博客和我的上一篇Mac下跑仅CPU模式下的PVANET陪过过程大致基本相同。但为了更好更流畅的配置py-faster-rcnn,这里记录下详细过程(坑)

1、还是安装依赖库

详见我的博客Mac下安装Caffe—CPU ONLY

2、确认安装Cython easydict protobuf

3、pull py-faster-rcnn

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

4、编译Cython modules

首先,打开./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']]#)

然后,cd 到 lib目录下执行make warning可以忽略

5、彻底修改Makefile.config 减少后面错误

因为Mac本身自带python2版本,而我自己使用anaconda安装python(这里建议使用2.7)python3尽管更新快,但是工程上更多是python2.这个就像opencv2在工程上使用率高一样
1. 备份系统python
$:sudo mv /System/Library/Frameworks/Python.framework
/System/Library/Frameworks/Python.framework_bak
2. 确认anaconda python 路径
3. 修改Makefile.config

step1:
CPU_ONLY := 1
WITH_PYTHON_LAYER := 1

step2:
DUDA全部注释

step3:
BLAS配置

前三个配置可参考PVANET
step4:
PYTHON_INCLUDE
PYTHON_LIB
根据自己路径配置

step5:
#TEST_GPUID := 0

6. Build Caffe and pycaffe

cd到py-faster-rcnn下
make -j8 && make pycaffe

* 这里遇到一个新的问题*:“ImportError: numpy.core.multiarray failed to import”
我自己实在解决不掉,清空之前python 和路径,直接重新安装python。

注意这里为安全(未知错误)起见,在caffe-fast-rcnn目录下执行

cp -a .build_release/lib/. /usr/local/lib/

7、Run Demo

准备工作
1、修改nms_wrapper.py
这里写图片描述
2 下载faster_rcnn_models
3.运行python ./tools/demo.py –cpu,OK
这里写图片描述

6.如有问题,欢迎留言指教。

原创粉丝点击