日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

编译py-faster-rcnn全过程

發布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 编译py-faster-rcnn全过程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

編譯py-faster-rcnn,花費了好幾天,中間遇到好多問題,今天終于成功編譯。下面詳述我的整個編譯過程。

【注記:】其實下面的依賴庫可以安裝在統一的一個本地目錄下,相關安裝指南,可以參考《深度學習:21天實戰caffe》的第5天那一章。 (這也是我后來才知道的。)
部分軟件見百度云盤:鏈接: https://pan.baidu.com/s/1kwucs_pDqM-5vN6NbVuLNg 密碼: fk0v

# 硬件情況
  • centos6.9
  • 8塊Titan xp顯卡

    [關于nvidia顯卡的對比,可以查看《nvidia顯卡對比分析》]

軟件情況

  • boost 1.41

    關于boost的情況,雖然caffe官網要求boost>=1.55,但是似乎對于低版本的也沒有出現什么問題,如果要安裝boost,可以參考《centos 安裝boost》,切記要原封不動地安裝如上說明去裝,否則有可能只裝上頭文件,卻沒有動態庫.就裝在默認目錄下即可。
    一般安裝好以后,頭文件在/usr/include/boost,lib文件在/usr/lib64/boost 。

  • OpenBlas

  • CUDA8.0

  • cudnn v6 (如果沒有安裝,可以自己裝在home目錄下,可參考< cuda、cudnn相關問題鏈接>)
    查看相應版本號:

cuda 版本 cat /usr/local/cuda/version.txt cudnn 版本 cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
  • glog
  • gflags

    注意要先安裝gflags,再安裝glog。安裝后者時,注意指定前者的路徑,如下:

./configure --prefix=/home/caiyong.wang/bin/caffe_local_install/ CPPFLAGS="-I/home/caiyong.wang/bin/caffe_local_install/include" LDFLAGS="-L/home/caiyong.wang/bin/caffe_local_install/lib"

  • leveldb
    安裝可以使用yum install
sudo yum install leveldb-devel

或者參考《levelDB的安裝-Linux》

  • lmdb
    使用pip安裝:
pip install lmdb
  • snappy
    首先下載snappy-1.1.1,然后解壓,配置:./configure --prefix=/home/**/
    最后編譯安裝: make && make install

以上關于依賴庫的安裝,可以參考:RHEL / Fedora / CentOS Installation

安裝依賴庫

  • anaconda2
    首先安裝anaconda2,安裝方法很簡單,就是下載軟件,然后運行 bash Anaconda2-5.0.0.1-Linux-x86_64.sh,接著安裝過程中,需要指定安裝路徑和選擇加入path環境變量(填yes),即可。重啟后,發現python變成anaconda的版本。
  • opencv-python
    使用pip安裝:
  • pip install opencv-python ,最新版為opencv3

    安裝后

    >>> import cv2 >>> print cv2.__version__

    注意:在caffe中不用麻煩地安裝源碼裝opencv,會很麻煩,要裝一堆依賴庫,而且很多需要sudo權限,
    請參考< linux 安裝python-opencv>
    3. easydict

    pip install easydict

    使用上述命令即可安裝成功。
    4. protobuf 2.6.1
    首先先確認系統是否有裝protobuf ,
    查看方法:

    $ protoc --version libprotoc 2.3.0

    如果沒有顯示,則說明沒有裝,另外我們期望裝2.6.1(caffe-master使用的protobuf版本是2.5.0及以上),所以版本不符,就需要重裝。
    注意要裝兩個probobuf,一個是python的,一個是系統的。而且最好安裝2.6.1,比較穩定。

    由于anaconda默認沒有裝protobuf,所以可以使用pip安裝指定版本的protobuf。
    [python版本]

    pip install protobuf==2.6.1

    [系統]
    從http://download.csdn.net/download/liangyihuai/9534593下載protobuf-2.6.1或從其他地方下載protobuf-2.6.1·.tar.gz。
    認真閱讀gitHub上給出的安裝教程。

    $./autogen.sh(在csdn下載的可以省略) $./configure --prefix=/home/**/protobuf (自己的目錄下) $ make $ make check $ make install

    編譯成功后將export PATH=/home/**/protobuf/bin:$PATH加入到環境變量中

    輸入 protoc --version命令,如顯示protobuf 2.6.1則安裝成功。

    $ protoc --version libprotoc 2.6.1

    最后進入caffe根目錄,修改Makefile.config,在INCLUDE_DIRS后面加入/home//protobuf/include
    LIBRARY_DIRS 后面加入 /home//protobuf/lib。
    【注意:】
    在向path中添加變量的時候,我總結一個原則,即:如果系統的路徑,比如/usr/local/bin等,就這樣寫:

    export PATH=$PATH:/usr/local/bin

    or

    export PATH=/usr/local/bin:$PATH

    如果是自己安裝的路徑,就:

    export PATH=/home/**/protobuf/bin:$PATH

    也就是一個在前一個在后的問題。之所以強調這個,是因為有時候系統已經安裝了某個軟件,如果你想覆蓋它,則在path中必須寫在它的前面。因此對于自己安裝的路徑,一般我們都想覆蓋原來的軟件,所以寫在path前面。,而系統安裝的軟件只有一個,寫在前后都可以。我們可以查看echo $PATH 來看最后的path路徑結果,并在需要的時候,在~/.bashrc中做相應地調整。一定要注意:
    對于含有兩個安裝位置的軟件,如果我們想先讀某一個,一定要注意在path的位置。

    make check的結果:

    5. hdf5
    由于前面安裝過 anaconda ,所以hdf5已經默認安裝。只需要把/*/anaconda2/lib 加入~/.bashrc中,即:

    export LD_LIBRARY_PATH=/*/anaconda2/lib:$LD_LIBRARY_PATH

    便于搜索hdf5的lib,尤其是 libhdf5_hl.so.100 ,若在后面的編譯中仍然找不到此lib的話,只能在home目錄下重新安裝,參考:http://blog.csdn.net/xiamentingtao/article/details/78266153
    6. 關于numpy的版本問題
    根據py-faster-rcnn的要求:

    numpy>=1.7.1

    但是anaconda最新默認裝的numpy的版本在1.13.1,雖然符合要求,但是https://github.com/rbgirshick/py-faster-rcnn/issues/480 ,最好numpy的版本為1.11.0,我們可以使用如下命令降級:

    pip install -U numpy==1.11.0

    下載py-faster-rcnn

    克隆Faster R-CNN倉庫:

    # Make sure to clone with --recursive git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

    –recursive :是為了遞歸下載caffe-master

    繼續安裝python依賴庫

    將上面的克隆的文件放在安裝目錄下,這里我們用FRCN_ROOT指 py-faster-rcnn的路徑,也就是

    進入根目錄,然后進入py-faster-rcnn/caffe-fast-rcnn/python中,caffe-fast-rcnn/python/requirement.txt文件列出了pycaffe的所有依賴庫,要把requirements下的依賴都裝一遍

    Cython>=0.19.2 numpy>=1.7.1 scipy>=0.13.2 scikit-image>=0.9.3 matplotlib>=1.3.1 ipython>=3.0.0 h5py>=2.2.0 leveldb>=0.191 networkx>=1.8.1 nose>=1.3.0 pandas>=0.12.0 python-dateutil>=1.4,<2 protobuf>=2.5.0 python-gflags>=2.0 pyyaml>=3.10 Pillow>=2.3.0 six>=1.1.0

    執行bash命令:

    $for req in $(cat requirements.txt); do pip install $req; done

    如果安裝完成,可以再運行一遍上述命令,發現全部裝好:

    運行pip list可以列出相應地版本號,要注意與上面說的相符,尤其是:protobuf 2.6.1

    到目前為止,我們可以對照caffe 官網的install,檢測所有必須的依賴庫。

    合版本

    根據《使用cuDNN5編譯py-faster-rcnn錯誤:cudnn.hpp(126): error: argument of type “int” is incompatible …》的要求去操作即可。

    或者參考http://blog.csdn.net/u010733679/article/details/52221404 更新最新的cudnn支持。

    編譯Cython模塊

    cd $FRCN_ROOT/lib make

    如果出現問題,參考:《 編譯py-faster-rcnn的問題匯總及解決方法》.

    編譯caffe& pycaffe

    正如caffe官網-install所說,在編譯前有兩種方法可以配置build,
    第一種就是常見的手動設置Makefile.(我所采用的)

    cp Makefile.config.example Makefile.config # Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired) make all make test make runtest make pycaffe

    另一種就是先用cmake(版本>=2.8.7)自動檢測各依賴項位置,生成Makefile.也可以自己設置。使用cmake-gui可能更容易些。

    mkdir build cd build #編譯CPU版本 #cmake -DCPU_ONLY=ON -DBLAS=Open . #編譯GPU版本 $cmake -DBLAS=Open -DCUDA_NVCC_FLAGS=--Wno-deprecated-gpu-targets .. make all make install make runtest make pycaffe

    下面給出我自己配置的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 layersUSE_OPENCV := 0USE_LEVELDB := 1USE_LMDB := 1# 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 := open # Custom (MKL/ATLAS/OpenBLAS) include and lib directories. # Leave commented to accept the defaults for your choice of BLAS # (which should work)! BLAS_INCLUDE := /opt/OpenBLAS/include BLAS_LIB := /opt/OpenBLAS/lib# 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 := /data1/caiyong.wang/bin/matlab # 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 := /data1/caiyong.wang/bin/anaconda2PYTHON_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/libPYTHON_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/local/include /data1/caiyong.wang/bin/hdf5-1.10.1/hdf5/include /data1/caiyong.wang/bin/protobuf/include LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /data1/caiyong.wang/bin/hdf5-1.10.1/hdf5/lib /data1/caiyong.wang/bin/protobuf/lib# 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 := 1BUILD_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 ?= @

    需要注意的是我禁掉了opencv,并且 加入了一些額外的搜索路徑,

    至于到底是否需要增加,我也不清楚。也許不用添加也可以。你可以自己嘗試。
    下面再貼出我的~/.bashrc的內容:

    # .bashrc# Source global definitions if [ -f /etc/bashrc ]; then. /etc/bashrc fi# User specific aliases and functionsalias matlab='/data1/caiyong.wang/bin/matlab/bin/matlab' export PYTHONPATH=/data1/caiyong.wang/program/faster_rcnn/py-faster-rcnn/caffe-fast-rcnn/python:$PYTHONPATHexport LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH# libglog export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH# hdf5 (其實可以省略,因為anaconda的lib含有,而且在下面一句已經加上,且加在了自安裝的HDF5的前面,所以實際上使用的仍然是anaconda的 版本,如果不行就加上唄。) #export LD_LIBRARY_PATH=/data1/caiyong.wang/bin/hdf5-1.10.1/hdf5/lib:$LD_LIBRARY_PATHexport LD_LIBRARY_PATH=/data1/caiyong.wang/bin/anaconda2/lib:$LD_LIBRARY_PATHexport PATH=/usr/local/cuda-8.0/bin:$PATH######## add protobuf lib path ######## ##(動態庫搜索路徑) 程序加載運行期間查找動態鏈接庫時指定除了系統默認路徑之外的其他路徑 #export LD_LIBRARY_PATH=/data1/caiyong.wang/bin/protobuf2/lib/:$LD_LIBRARY_PATH ##(靜態庫搜索路徑) 程序編譯期間查找動態鏈接庫時指定查找共享庫的路徑 #export LIBRARY_PATH=/data1/caiyong.wang/bin/protobuf2/lib/:$LIBRARY_PATH ##執行程序搜索路徑 #export PATH=/data1/caiyong.wang/bin/protobuf2/bin/:$PATH ##c程序頭文件搜索路徑 #export C_INCLUDE_PATH=/data1/caiyong.wang/bin/protobuf2/include/:$C_INCLUDE_PATH ##c++程序頭文件搜索路徑 #export CPLUS_INCLUDE_PATH=/data1/caiyong.wang/bin/protobuf2/include/:$CPLUS_INCLUDE_PATH ##pkg-config 路徑 #export PKG_CONFIG_PATH=/data1/caiyong.wang/bin/protobuf2/lib/pkgconfig/ ####################################### #alias protoc='/data1/caiyong.wang/bin/protobuf2/bin/protoc' export PATH=/data1/caiyong.wang/bin/protobuf/bin:$PATH export PATH=/usr/local/bin:$PATH export LD_LIBRARY_PATH=/data1/caiyong.wang/bin/protobuf/lib:$LD_LIBRARY_PATH# added by Anaconda2 installer export PATH=/data1/caiyong.wang/bin/anaconda2/bin:$PATH

    一般情況下,這樣編譯就可以通過。這里make runtest花費時間很多,我用了近9個小時。如果不想花費這么長時間,也可以不運行這個指令。

    最后為了在python中可以載入caffe模塊,我們需要在bashrc設置PYTHONPATH。

    export PYTHONPATH=/*/py-faster-rcnn/caffe-fast-rcnn/python:$PYTHONPATH

    然后source ~/.bashrc生效。

    最終查看python接口是否編譯成功:

    進入python環境,進行import操作

    # python >>> import caffe >>> print caffe.__version__ 1.0.0

    如果沒有提示錯誤,則編譯成功。

    測試demo

  • 下載預計算的R-CNN檢測器
  • cd $FRCN_ROOT ./data/scripts/fetch_faster_rcnn_models.sh

    這個模型解壓出來750M,下載的話大概695M,而且很慢。。
    為了方便大家,我把模型上傳到了百度云 鏈接: https://pan.baidu.com/s/1eSKoVAi 密碼: 59ga
    注意下載后,解壓到data目錄下。
    2. 運行

    cd $FRCN_ROOT ./tools/demo.py

    出現結果: (共5個圖片來源)

    [外鏈圖片轉存失敗(img-Dv5lyU7I-1567741174724)(https://img-blog.csdn.net/20171019152755856?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGlhbWVudGluZ3Rhbw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)]

    成功~~~

    最后說明

    如果安裝過程中還有問題,可以參考:http://blog.csdn.net/xiamentingtao/article/details/78266153

    參考文獻

    • rbgirshick/py-faster-rcnn
    • cuda8+cudnn4 Faster R-CNN安裝塈運行demo
    • 使用cuDNN5編譯py-faster-rcnn錯誤:cudnn.hpp(126): error: argument of type “int” is incompatible …
    • Caffe-faster-rcnn demo測試
    • caffe官網-install
    • Caffe學習系列(13):數據可視化環境(python接口)配置

    總結

    以上是生活随笔為你收集整理的编译py-faster-rcnn全过程的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。