Advertisement

Ubuntu 18.04配置caffe和运行py-faster-rcnn

阅读量:

Step1:安装调试Caffe

基本信息:

Ubuntu 18.04

NVIDIA官网下载CUDA 10.0 ,Nvidia Driver 410.73 ,cudnn下载安装相对应版本就可以,安装教程不赘述。

下载caffe:

  • Caffe在GitHub上源码下载:https://github.com/BVLC/caffe 解压后文件名是caffe-master,放在合适的位置
  • 在anaconda中创建单独的环境,安装的是Python2.7,还需要安装在caffe-master/python/requirements.txt一些编译时会用到的包,caffe安装说明里有咖啡说明。或者说我们直接在anaconda环境中自己安装上也行。
复制代码
 # 激活anaconda中的环境变量,ff是你自己取得环境变量名。

    
 source activate ff
    
 # 再cd进入caffe-master目录下
    
 cd caffe-master/
复制代码
 # 复制一下Makefile.config.example文件,去掉.cpnfig,这是因为编译的时候不能

    
 # 识别出.example结尾的文件,之所以用.example,就是一个示例而已,需要我们自己根据实际电脑设置的环境做出改动。
    
 cp Makefile.config.example Makefile.config
    
 # 进入Makefile.config文件进行一些参数更改
    
 vi 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
    
 # This code is taken from https://github.com/sh1r0/caffe-android-lib
    
 # USE_HDF5 := 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/local/cuda-10.0
    
 # CUDA architecture setting: going with all of them.
    
 # For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
    
 # For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
    
 # For CUDA >= 9.0, comment the *_20 and *_21 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_52,code=sm_52 \
    
   -gencode arch=compute_60,code=sm_60 \
    
   -gencode arch=compute_61,code=sm_61 \
    
   -gencode arch=compute_61,code=compute_61
    
  
    
 # 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 := /path/to/your/blas
    
 # BLAS_LIB := /path/to/your/blas
    
  
    
 # 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/lib/python2.7/dist-packages/numpy/core/include
    
 # Anaconda Python distribution is quite popular. Include path:
    
 # Verify anaconda location, sometimes it's in root.
    
 ANACONDA_HOME := $(HOME)/anaconda3
    
 PYTHON_INCLUDE := $(ANACONDA_HOME)/envs/ff/include/python2.7 \
    
      $(HOME)/anaconda3/envs/ff/lib/python2.7/site-packages/numpy/core/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 /home/changdefan/anaconda3/envs/myrcnn_env/bin/python3.6m
    
 # PYTHON_INCLUDE := $(HOME)/anaconda3/envs/myrcnn_env/include/python3.6m \
    
   #              $(HOME)/anaconda3/envs/ff/lib/python2.7/site-packages/numpy/core/include
    
  
    
 # We need to be able to find libpythonX.X.so or .dylib.
    
 #PYTHON_LIB := /usr/lib
    
 PYTHON_LIB := $(HOME)/anaconda3/envs/ff/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/local/include /usr/include /home/c410/anaconda3/envs/ff/include /usr/include/hdf5/serial# (which should work)!
    
 # BLAS_INCLUDE := /path/to/your/blas
    
 # BLAS_LIB := /path/to/your/blas
    
  
    
 # 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/lib/python2.7/dist-packages/numpy/core/include
    
 # Anaconda Python distribution is quite popular. Include path:
    
 # Verify anaconda location, sometimes it's in root.
    
 ANACONDA_HOME := $(HOME)/anaconda3
    
 PYTHON_INCLUDE := $(ANACONDA_HOME)/envs/ff/include/python2.7 \
    
      $(HOME)/anaconda3/envs/ff/lib/python2.7/site-packages/numpy/core/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 /home/changdefan/anaconda3/envs/myrcnn_env/bin/python3.6m
    
 # PYTHON_INCLUDE := $(HOME)/anaconda3/envs/myrcnn_env/include/python3.6m \
    
   #              $(HOME)/anaconda3/envs/ff/lib/python2.7/site-packages/numpy/core/include
    
  
    
 # We need to be able to find libpythonX.X.so or .dylib.
    
 #PYTHON_LIB := /usr/lib
    
 PYTHON_LIB := $(HOME)/anaconda3/envs/ff/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/local/include /usr/include /home/c410/anaconda3/envs/ff/include /usr/include/hdf5/serial
    
 LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
    
  
    
 # 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
    
  
    
 # NCCL acceleration switch (uncomment to build with NCCL)
    
 # https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
    
 # USE_NCCL := 1
    
  
    
 # 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
    
  
    
 # N.B. both build and distribute dirs are cleared on `make clean`
    
 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.config文件做出的修改,有一些是默认的不需要改动,因为我是在anaconda里配置的Python2环境,从上面的代码可以清楚看出来我的配置路径,只要根据你的实际情况做出修改就可以。对于Makefile文件,网上很多说需要更改,但是我这里基本没有改动,最后也运行成功了,所以就没贴出代码。如果有需要,后面遇到问题的时候再具体去谷歌,Bing等搜索解决。
复制代码
 # 进入caffe-master文件

    
 make clean
    
 # 再输入如下代码,8这个数字意思是CPU加速,如果不加速的话直接make all也是可以的,只不过比较慢但是可以一条条编译,
    
 # 然后一出现问题程序就会终止,如果是加速的话会一下子出现好几个问题,笔者当时看着这些错误头很大
    
 make all -j8
    
  
    
 # 上述成功后,输入如下代码,如果不报错就说明编译成功
    
 make pycaffe
  • 第一次运行的话一般会出现错误,但是请不用着急。在配置的时候遇到一个最麻烦的问题就是protobuf,我在环境里安装的3.0.0版本,务必在环境外的系统中也讲protobuf版本设为3.0.0的。还有一些其它问题,我会在之后补充。
    • 编译完,现在就在环境中输入Python,试着导入import caffe,如果不报错就说明成功。

Step2:运行py-faster-rcnn中的demo.py

  • GitHub下载RBG大神的py-faster-rcnn,根据里面的README.md要求下载。推荐如下方法:
复制代码
 git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

    
  
    
 # 下载完之后,cd $FRCN_ROOT/lib(别忘记这时候是在anaconda创建的环境变量中的。)
    
 make
  • 接着把之前编译好的caffe-master里的Makefile.config文件复制到FRCN_ROOT/caffe-fast-rcnn里,接着再编译一次。
复制代码
 # 编译,正常的话运行下列代码是不会出错的,相当于将之前编译成功的caffe文件再编译一次而已

    
 cd $FRCN_ROOT/caffe-fast-rcnn
    
  
    
 make -j8 && make pycaffe
  • 接着README上是./data/scripts/fetch_faster_rcnn_models.sh模型下载,但是这个.sh文件里的文件地址已经出错,这里给出地址。下载完解压一定要在终端用命令解压,tar -zxvf faster_rcnn_models放在$FRCN_ROOT/data下。
复制代码
 cd $FRCN_ROOT

    
 ./tools/demo.py

总结:

  • 编译的时候错误会很多,但是希望要用耐心解决。

全部评论 (0)

还没有任何评论哟~