zoukankan      html  css  js  c++  java
  • Faster R-CNN安装笔记,只用CPU

    转自:http://blog.sina.com.cn/s/blog_679f93560102wpyf.html

    • 下载代码和数据
     
    • 下载demo模型数据
    [root@localhost py-faster-rcnn]# ./data/scripts/fetch_faster_rcnn_models.sh
    Downloading Faster R-CNN demo models (695M)...
    。。。
    Unzipping...
    faster_rcnn_models/
    faster_rcnn_models/ZF_faster_rcnn_final.caffemodel
    faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel
     
     
    • 编译cython
    进入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']]
    #    ),
    。。。
     
    编译:
    [root@localhost lib]# make
     
    • 安装caffe(自带的,不是通用的)
    进入caffe-fast-rcnn目录,大部分跟前面caffe安装记录一文一样,修改Makefile.config为
     
    ## Refer to http://caffe.berkeleyvision.org/installation.html
    # Contributions simplifying and improving our build system are welcome!
     
    # cuDNN acceleration switch (uncomment to build with cuDNN).
    # USE_CUDNN := 1
     
    # CPU-only switch (uncomment to build without GPU support).
    CPU_ONLY := 1
     
    # uncomment to disable IO dependencies and corresponding data layers
    # USE_OPENCV := 0
    # USE_LEVELDB := 0
    # USE_LMDB := 0
     
    # uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
    #    You should not set this flag if you will be reading LMDBs with any
    #    possibility of simultaneous read and write
    # ALLOW_LMDB_NOLOCK := 1
     
    # Uncomment if you're using OpenCV 3
    # OPENCV_VERSION := 3
     
    # To customize your choice of compiler, uncomment and set the following.
    # N.B. the default for Linux is g++ and the default for OSX is clang++
    # CUSTOM_CXX := g++
     
    # CUDA directory contains bin/ and lib/ directories that we need.
    # CUDA_DIR := /usr/local/cuda
    # On Ubuntu 14.04, if cuda tools are installed via
    # "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
    # CUDA_DIR := /usr
     
    # CUDA architecture setting: going with all of them.
    # For CUDA < 6.0, comment the *_50 lines for compatibility.
    #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
     
    # BLAS choice:
    # atlas for ATLAS (default)
    # mkl for MKL
    # open for OpenBlas
    BLAS := atlas
    # Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
    # Leave commented to accept the defaults for your choice of BLAS
    # (which should work)!
    BLAS_INCLUDE := /usr/include/atlas-x86_64-base
    BLAS_LIB := /usr/lib64/atlas
     
    # Homebrew puts openblas in a directory that is not on the standard search path
    # BLAS_INCLUDE := $(shell brew --prefix openblas)/include
    # BLAS_LIB := $(shell brew --prefix openblas)/lib
     
    # This is required only if you will compile the matlab interface.
    # MATLAB directory should contain the mex binary in /bin.
    # MATLAB_DIR := /usr/local
    # MATLAB_DIR := /Applications/MATLAB_R2012b.app
     
    # NOTE: this is required only if you will compile the python interface.
    # We need to be able to find Python.h and numpy/arrayobject.h.
    PYTHON_INCLUDE := /usr/include/python2.7
                      /usr/lib64/python2.7/site-packages/numpy/core/include
    # Anaconda Python distribution is quite popular. Include path:
    # Verify anaconda location, sometimes it's in root.
    # ANACONDA_HOME := $(HOME)/anaconda
    # PYTHON_INCLUDE := $(ANACONDA_HOME)/include
            # $(ANACONDA_HOME)/include/python2.7
            # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
     
    # Uncomment to use Python 3 (default is Python 2)
    # PYTHON_LIBRARIES := boost_python3 python3.5m
    # PYTHON_INCLUDE := /usr/include/python3.5m
    #                 /usr/lib/python3.5/dist-packages/numpy/core/include
     
    # We need to be able to find libpythonX.X.so or .dylib.
    PYTHON_LIB := /usr/lib64
    # PYTHON_LIB := $(ANACONDA_HOME)/lib
     
    # Homebrew installs numpy in a non standard path (keg only)
    # PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
    # PYTHON_LIB += $(shell brew --prefix numpy)/lib
     
    # Uncomment to support layers written in Python (will link against Python libs)
    WITH_PYTHON_LAYER := 1
     
    # Whatever else you find you need goes here.
    INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/include
    LIBRARY_DIRS := $(PYTHON_LIB) /usr/lib64
     
    # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
    # INCLUDE_DIRS += $(shell brew --prefix)/include
    # LIBRARY_DIRS += $(shell brew --prefix)/lib
     
    # Uncomment to use `pkg-config` to specify OpenCV library paths.
    # (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
    # USE_PKG_CONFIG := 1
     
    BUILD_DIR := build
    DISTRIBUTE_DIR := distribute
     
    # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
    # DEBUG := 1
     
    # The ID of the GPU that 'make runtest' will use to run unit tests.
    # TEST_GPUID := 0
     
    # enable pretty build (comment to see full commands)
    Q ?= @
     
    修改Makefile
    LIBRARIES += satlas tatlas #新版atlas已经不用这两个lib了:cblas atlas
     
    编译caffe和pycaffe
     [root@localhost caffe-fast-rcnn]# make -j8 && make pycaffe
     
    • 跑demo
    [root@localhost py-faster-rcnn]# ./tools/demo.py
    Traceback (most recent call last):
    File "./tools/demo.py", line 17, in
     from fast_rcnn.config import cfg
     File "/root/zhanxiang/work/py-faster-rcnn/tools/../lib/fast_rcnn/config.py", line 23, in
    from easydict import EasyDict as edict
    ImportError: No module named easydict
     
    缺少Python库easydict,所以安装 pip install easydict
     
    [root@localhost py-faster-rcnn]# ./tools/demo.py
    Traceback (most recent call last):
      File "./tools/demo.py", line 18, in
        from fast_rcnn.test import im_detect
      File "/root/zhanxiang/work/py-faster-rcnn/tools/../lib/fast_rcnn/test.py", line 15, in
        import cv2
    ImportError: No module named cv2
     
    缺少Python库cv2,这个是openCV里面的。那就来装openCV python库
    yum install opencv-python.x86_64
     
    [root@localhost py-faster-rcnn]# python tools/demo.py --cpu
    Traceback (most recent call last):
      File "tools/demo.py", line 21, in
        import matplotlib.pyplot as plt
      File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 26, in
        from matplotlib.figure import Figure, figaspect
      File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 36, in
        from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
      File "/usr/lib64/python2.7/site-packages/matplotlib/axes/__init__.py", line 4, in
        from ._subplots import *
      File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_subplots.py", line 10, in
        from matplotlib.axes._axes import Axes
      File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_axes.py", line 14, in
        from matplotlib import unpack_labeled_data
    ImportError: cannot import name unpack_labeled_data
     
    看起来跟matplotlib库有关,pip install的版本太旧,直接下载源码安装
     
    [root@localhost work]# git clone git://github.com/matplotlib/matplotlib.git
    [root@localhost work]# cd matplotlib/
    安装依赖包
    [root@localhost matplotlib]# yum-builddep python-matplotlib
    安装
    [root@localhost matplotlib]# python setup.py install
     
    [root@localhost py-faster-rcnn]# python tools/demo.py --cpu
    Traceback (most recent call last):
      File "tools/demo.py", line 19, in
        from fast_rcnn.nms_wrapper import nms
      File "/root/zhanxiang/work/py-faster-rcnn/tools/../lib/fast_rcnn/nms_wrapper.py", line 9, in
        from nms.gpu_nms import gpu_nms
    ImportError: No module named gpu_nms
     
    修改nms_wrapper.py,改force_cpu =True
    [root@localhost py-faster-rcnn]# vi lib/fast_rcnn/nms_wrapper.py
    def nms (dets, thresh, force_cpu =True):
     
    • 大功告成
    [root@localhost py-faster-rcnn]# python tools/demo.py --cpu
    就能看到结果了

     

    更多资源:http://www.cnblogs.com/justinzhang/p/5386837.html

  • 相关阅读:
    Net设计模式实例之命令模式(Command Pattern)
    Jquery实现回车键Enter切换焦点
    Asp.net MVC2.0系列文章显示列表和详细页面操作
    [入门篇]Jquery读取.Net WebService Json数据
    Net设计模式实例之中介者模式(Mediator Pattern)
    26个Jquery使用小技巧(jQuery tips, tricks & solutions)
    虚拟化让私有云逐步落地
    Jquery打造AdRotator轮转图片
    360度全方位沟通向上领导法则一
    使用Jquery+CSS如何创建流动导航菜单Fluid Navigation
  • 原文地址:https://www.cnblogs.com/xiaoming123abc/p/5823682.html
Copyright © 2011-2022 走看看