编译py-faster-rcnn全过程
編譯py-faster-rcnn,花費了好幾天,中間遇到好多問題,今天終于成功編譯。下面詳述我的整個編譯過程。
【注記:】其實下面的依賴庫可以安裝在統(tǒng)一的一個本地目錄下,相關安裝指南,可以參考《深度學習:21天實戰(zhàn)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》,切記要原封不動地安裝如上說明去裝,否則有可能只裝上頭文件,卻沒有動態(tài)庫.就裝在默認目錄下即可。
一般安裝好以后,頭文件在/usr/include/boost,lib文件在/usr/lib64/boost 。 -
OpenBlas
-
CUDA8.0
-
cudnn v6 (如果沒有安裝,可以自己裝在home目錄下,可參考< cuda、cudnn相關問題鏈接>)
查看相應版本號:
- 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
或者參考《levelDB的安裝-Linux》
- lmdb
使用pip安裝:
- snappy
首先下載snappy-1.1.1,然后解壓,配置:./configure --prefix=/home/**/
最后編譯安裝: make && make install
以上關于依賴庫的安裝,可以參考:RHEL / Fedora / CentOS Installation
安裝依賴庫
首先安裝anaconda2,安裝方法很簡單,就是下載軟件,然后運行 bash Anaconda2-5.0.0.1-Linux-x86_64.sh,接著安裝過程中,需要指定安裝路徑和選擇加入path環(huán)境變量(填yes),即可。重啟后,發(fā)現python變成anaconda的版本。
使用pip安裝:
安裝后
>>> import cv2 >>> print cv2.__version__注意:在caffe中不用麻煩地安裝源碼裝opencv,會很麻煩,要裝一堆依賴庫,而且很多需要sudo權限,
請參考< linux 安裝python-opencv>
3. easydict
使用上述命令即可安裝成功。
4. protobuf 2.6.1
首先先確認系統(tǒng)是否有裝protobuf ,
查看方法:
如果沒有顯示,則說明沒有裝,另外我們期望裝2.6.1(caffe-master使用的protobuf版本是2.5.0及以上),所以版本不符,就需要重裝。
注意要裝兩個probobuf,一個是python的,一個是系統(tǒng)的。而且最好安裝2.6.1,比較穩(wěn)定。
由于anaconda默認沒有裝protobuf,所以可以使用pip安裝指定版本的protobuf。
[python版本]
[系統(tǒng)]
從http://download.csdn.net/download/liangyihuai/9534593下載protobuf-2.6.1或從其他地方下載protobuf-2.6.1·.tar.gz。
認真閱讀gitHub上給出的安裝教程。
編譯成功后將export PATH=/home/**/protobuf/bin:$PATH加入到環(huán)境變量中
輸入 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中添加變量的時候,我總結一個原則,即:如果系統(tǒng)的路徑,比如/usr/local/bin等,就這樣寫:
or
export PATH=/usr/local/bin:$PATH如果是自己安裝的路徑,就:
export PATH=/home/**/protobuf/bin:$PATH也就是一個在前一個在后的問題。之所以強調這個,是因為有時候系統(tǒng)已經安裝了某個軟件,如果你想覆蓋它,則在path中必須寫在它的前面。因此對于自己安裝的路徑,一般我們都想覆蓋原來的軟件,所以寫在path前面。,而系統(tǒng)安裝的軟件只有一個,寫在前后都可以。我們可以查看echo $PATH 來看最后的path路徑結果,并在需要的時候,在~/.bashrc中做相應地調整。一定要注意:
對于含有兩個安裝位置的軟件,如果我們想先讀某一個,一定要注意在path的位置。
make check的結果:
5. hdf5
由于前面安裝過 anaconda ,所以hdf5已經默認安裝。只需要把/*/anaconda2/lib 加入~/.bashrc中,即:
便于搜索hdf5的lib,尤其是 libhdf5_hl.so.100 ,若在后面的編譯中仍然找不到此lib的話,只能在home目錄下重新安裝,參考:http://blog.csdn.net/xiamentingtao/article/details/78266153
6. 關于numpy的版本問題
根據py-faster-rcnn的要求:
但是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
繼續(xù)安裝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執(zhí)行bash命令:
$for req in $(cat requirements.txt); do pip install $req; done如果安裝完成,可以再運行一遍上述命令,發(fā)現全部裝好:
運行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.(我所采用的)
另一種就是先用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的內容:
一般情況下,這樣編譯就可以通過。這里make runtest花費時間很多,我用了近9個小時。如果不想花費這么長時間,也可以不運行這個指令。
最后為了在python中可以載入caffe模塊,我們需要在bashrc設置PYTHONPATH。
然后source ~/.bashrc生效。
最終查看python接口是否編譯成功:
進入python環(huán)境,進行import操作
# python >>> import caffe >>> print caffe.__version__ 1.0.0如果沒有提示錯誤,則編譯成功。
測試demo
這個模型解壓出來750M,下載的話大概695M,而且很慢。。
為了方便大家,我把模型上傳到了百度云 鏈接: https://pan.baidu.com/s/1eSKoVAi 密碼: 59ga
注意下載后,解壓到data目錄下。
2. 運行
出現結果: (共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):數據可視化環(huán)境(python接口)配置
總結
以上是生活随笔為你收集整理的编译py-faster-rcnn全过程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JQuery 中选择多选择框,和单选框,
- 下一篇: MySQL管理工具-SQLyog 9.6