• 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

  • 相关阅读:
    【Eclipse】怎样把代码复制到word中并保持颜色
    windows下配置gvim
    这是给开发者的弥天大谎还是至理名言?
    Linux中常用软件安装(基于Ubuntu)
    MyEclipse 9.1优化技巧
    【数据库复习】函数依赖
    Windows下使用Flex入门
    【数据库复习】SQL
    浏览器中的“Linux”
    Unity开发原则
  • 原文地址:https://www.cnblogs.com/xiaoming123abc/p/5823682.html
Copyright © 2020-2023  润新知