Faster RCNN CPU安装记录

参考博客:Faster-RCNN+ZF用自己的数据集训练模型(Python版本)

目前执行了2中的(1)(2),由于在make时遇到了错误(无GPU的原因),搜索了下面的博客进行安装

参考博客:Faster R-CNN算法的Caffe实现

  遇到的问题与相关不同:

1、cython编译出错

python setup.py build_ext --inplace
Traceback (most recent call last):
  File "setup.py", line 56, in <module>
    CUDA = locate_cuda()
  File "setup.py", line 44, in locate_cuda
    raise EnvironmentError('The nvcc binary could not be '
EnvironmentError: The nvcc binary could not be located in your $PATH. Either add it to your path, or set $CUDAHOME
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1
解决方案:

        1)注释掉setup.py中的CUDA = locate_cuda()

      报错:

python setup.py build_ext --inplace
Traceback (most recent call last):
  File "setup.py", line 125, in <module>
    library_dirs=[CUDA['lib64']],
NameError: name 'CUDA' is not defined
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1

      2)寻找setup中所有与gpu有关的代码 注释掉

#    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']]
#    ),
提示:(这应该是成功了吧)
python setup.py build_ext --inplace
running build_ext
cythoning utils/bbox.pyx to utils/bbox.c
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/home/lys/.local/lib/python2.7/site-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
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 /home/lys/py-faster-rcnn/lib/utils/cython_bbox.so
cythoning nms/cpu_nms.pyx to nms/cpu_nms.c
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/home/lys/.local/lib/python2.7/site-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
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 /home/lys/py-faster-rcnn/lib/nms/cpu_nms.so
cythoning pycocotools/_mask.pyx to pycocotools/_mask.c
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/home/lys/.local/lib/python2.7/site-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/home/lys/.local/lib/python2.7/site-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
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 /home/lys/py-faster-rcnn/lib/pycocotools/_mask.so
rm -rf build


2、Makefile.config 中的 CPU_ONLY=1的注释去掉

# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1
参考博客:Faster R-CNN CPU环境搭建

遇到的问题与相关不同

1、caffe、opencv之前安装完成,未执行1; caffe-fast-rcnn上一步make完成,未执行2

2、运行./fetch_faster_rcnn_models.sh 时连接超时

   解决:1)使用第一篇博客在评论中提供的下载地址下载py-faster-rcnn faster_rcnn_models.tgz。网址点击Download下载下来一个种子,使用百度云或者迅雷下载数据:

http://academictorrents.com/details/cca56021739c8a75af3b58f536d4930266c25d5e/tech

等待下载之余运行了一下demo.py出现了以下错误:缺少matplotlib,使用

sudo apt-get install python-matplotlib#安装matplotlib

Traceback (most recent call last):
  File "./demo.py", line 21, in <module>
    import matplotlib.pyplot as plt
  File "/home/lys/.local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/home/lys/.local/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/home/lys/.local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
    from six.moves import tkinter as Tk
  File "/home/lys/.local/lib/python2.7/site-packages/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/home/lys/.local/lib/python2.7/site-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/home/lys/.local/lib/python2.7/site-packages/six.py", line 82, in _import_module
    __import__(name)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in <module>
    raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk package

安装之后果然就是model还没下载的错误啦,安心等着下载完。。。。。。希望不会再出错,祈祷


下载完成后将压缩包解压到.../py-faster-rcnn/data/faster_rcnn_models,在.../py-faster-rcnn/tools/下运行 python demo.py --cpu

出现如下错误:

Traceback (most recent call last):
  File "/home/lys/py-faster-rcnn/tools/../lib/rpn/proposal_layer.py", line 10, in <module>
    import yaml
ImportError: No module named yaml
Traceback (most recent call last):
  File "demo.py", line 135, in <module>
    net = caffe.Net(prototxt, caffemodel, caffe.TEST)
SystemError: NULL result without error in PyObject_Call

使用sudo apt-get install python-yaml进行安装yaml(YAML是一种直观的能够被电脑识别的的数据序列化格式,容易被人类阅读,并且容易和脚本语言交互。YAML类似于XML,但是语法比XML简单得多,对于转化成数组或可以hash的数据时是很简单有效的.yaml在python中的使用 )

再次执行demo.py,运行成功。

复制一张博客的结果图,不知道结果存哪去了,好像并没有存

1

发布了32 篇原创文章 · 获赞 16 · 访问量 7万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章