Caffe Window 和 ubuntu編譯安裝

Caffe Window環境下搭建(CPU)

1.Caffe for windows下載地址:
   https://github.com/initialneil/caffe-vs2013
2.安裝所需依賴:
   CUDA6.5 for windows  https://developer.nvidia.com/cuda-downloads
   OpenCV 2.4.9 http://opencv.org/releases.html
   Boost 
   google protoBuff
   3ryparty.zip 下載解壓到3ryparty目錄下
   gflags   git clone https://github.com/gflags/gflags.git
   hdf5 https://support.hdfgroup.org/HDF5/release/obtain518.html
   glog http://download.csdn.net/download/chenguangxing3/6661667

   此處CUDA安裝時,如果顯卡不是GT系列的,使用自定義安裝,不安裝驅動,只安裝sample和toolkit 這樣雖不能使用GPU但可以編譯工程;


3.添加系統環境變量
   OPENCV_3_0_0 = “你的安裝路徑”
   BOOST_1_56_0 = “你的安裝路徑”   
   CUDA_PATH_V6_5 = “你的安裝路徑” 
   設置完系統環境變量後重啓機器,使其生效;
4.編譯工程:
  根據你的機器,設置編譯平臺,我這裏選擇x64
  (1)fatal error C1083: 無法打開包括文件: “gflags/gflags.h”: No such file or directory
  (2)無法打開包括文件: “hdf5/hdf5.h”: No such file or directoryD:\Meachine_learning\caffe-vs2013\caffe\src\caffe\layers\hdf5_data_layer.cu
  (3)fatal error C1083: 無法打開包括文件: “glog/logging.h”: No such file or directory

Caffe Linux install

轉載 :

https://www.zybuluo.com/hanxiaoyang/note/364737

參考:

https://github.com/BVLC/caffe


0.關於caffe(by@寒小陽)

caffe是深度學習在圖像領域廣泛使用的框架,其model zoo有大量的預訓練好的模型提供使用。圖像相關應用會大量使用到caffe。

牆裂建議大家使用linux系統,原因如下。

  • linux系統(大部分公司爲CentOS或者Ubuntu),纔是實際開發中用到的系統,提前熟悉一下命令行,對於實際應用和開發都很有必要。
  • 相對於Windows而言,linux下的依賴包安裝非常簡單。
  • Windows下編譯經常會出現大量問題,且現在網上Windows下caffe出現問題的解決方案非常少。
  • 大量的二次開發和擴展都只有linux版本。

1.說明

下面是安裝caffe的一些筆記,寫的不明白的,歡迎在社區發帖問,也方便更多的同學查看相同的問題^_^

2.關於系統

這個說明是關於linux系統的,最好是centOS 7.0以上,或者ubuntu 14.04 以上
因爲低版本的裝不上兼容合適的boost,opencv等庫

3.安裝依賴的庫

要確認一下,所有的庫都裝上了,否則編譯出來可能不能使用。
其中protobuf是用來定義layers的,leveldb是訓練時存儲圖片數據的數據庫,opencv是圖像處理庫,boost是通用C++庫,等等...

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler

sudo apt-get install --no-install-recommends libboost-all-dev

4.安裝科學計算和python所需的部分庫

sudo apt-get install openblas-dev numpy scipy matplotlib lapack-dev freetype-dev libpng-dev openblas-dev

5.安裝其餘依賴

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

6.安裝git,拉取源碼

apt-get install git

git clone https://github.com/BVLC/caffe.git

7.安裝python的pip和easy_install,方便安裝軟件包

wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
python ez_setup.py --insecure

wget https://bootstrap.pypa.io/get-pip.py

python get-pip.py

8.安裝python依賴(路徑根據自己的目錄可能要調一下)

cd caffe/python

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

這步安裝也有點慢,別急,等會兒,先去幹點別的 ^_^

9.編輯caffe所需的Makefile文件

cd caffe
cp Makefile.config.example Makefile.config
vim Makefile.config
Makefile.config裏面有依賴庫的路徑,及各種編譯配置,如果是沒有GPU的情況下,可以參照我下面幫你改的配置文件內容:

  1. ## Refer to http://caffe.berkeleyvision.org/installation.html
  2. # Contributions simplifying and improving our build system are welcome!
  3. # cuDNN acceleration switch (uncomment to build with cuDNN).
  4. # USE_CUDNN := 1
  5. # CPU-only switch (uncomment to build without GPU support).
  6. CPU_ONLY := 1
  7. # uncomment to disable IO dependencies and corresponding data layers
  8. # USE_OPENCV := 0
  9. # USE_LEVELDB := 0
  10. # USE_LMDB := 0
  11. # uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
  12. # You should not set this flag if you will be reading LMDBs with any
  13. # possibility of simultaneous read and write
  14. # ALLOW_LMDB_NOLOCK := 1
  15. # Uncomment if you're using OpenCV 3
  16. # OPENCV_VERSION := 3
  17. # To customize your choice of compiler, uncomment and set the following.
  18. # N.B. the default for Linux is g++ and the default for OSX is clang++
  19. # CUSTOM_CXX := g++
  20. # CUDA directory contains bin/ and lib/ directories that we need.
  21. CUDA_DIR := /usr/local/cuda
  22. # On Ubuntu 14.04, if cuda tools are installed via
  23. # "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
  24. # CUDA_DIR := /usr
  25. # CUDA architecture setting: going with all of them.
  26. # For CUDA < 6.0, comment the *_50 lines for compatibility.
  27. CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
  28. -gencode arch=compute_20,code=sm_21 \
  29. -gencode arch=compute_30,code=sm_30 \
  30. -gencode arch=compute_35,code=sm_35 \
  31. -gencode arch=compute_50,code=sm_50 \
  32. -gencode arch=compute_50,code=compute_50
  33. # BLAS choice:
  34. # atlas for ATLAS (default)
  35. # mkl for MKL
  36. # open for OpenBlas
  37. #BLAS := atlas
  38. BLAS := open
  39. # Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
  40. # Leave commented to accept the defaults for your choice of BLAS
  41. # (which should work)!
  42. # BLAS_INCLUDE := /path/to/your/blas
  43. # BLAS_LIB := /path/to/your/blas
  44. # Homebrew puts openblas in a directory that is not on the standard search path
  45. # BLAS_INCLUDE := $(shell brew --prefix openblas)/include
  46. # BLAS_LIB := $(shell brew --prefix openblas)/lib
  47. BLAS_INCLUDE := /usr/include/openblas
  48. # This is required only if you will compile the matlab interface.
  49. # MATLAB directory should contain the mex binary in /bin.
  50. # MATLAB_DIR := /usr/local
  51. # MATLAB_DIR := /Applications/MATLAB_R2012b.app
  52. # NOTE: this is required only if you will compile the python interface.
  53. # We need to be able to find Python.h and numpy/arrayobject.h.
  54. PYTHON_INCLUDE := /usr/include/python2.7 \
  55. /usr/lib/python2.7/dist-packages/numpy/core/include
  56. # Anaconda Python distribution is quite popular. Include path:
  57. # Verify anaconda location, sometimes it's in root.
  58. # ANACONDA_HOME := $(HOME)/anaconda
  59. # PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
  60. # $(ANACONDA_HOME)/include/python2.7 \
  61. # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \
  62. # We need to be able to find libpythonX.X.so or .dylib.
  63. PYTHON_LIB := /usr/lib
  64. # PYTHON_LIB := $(ANACONDA_HOME)/lib
  65. # Homebrew installs numpy in a non standard path (keg only)
  66. # PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
  67. # PYTHON_LIB += $(shell brew --prefix numpy)/lib
  68. # Uncomment to support layers written in Python (will link against Python libs)
  69. WITH_PYTHON_LAYER := 1
  70. # Whatever else you find you need goes here.
  71. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
  72. LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
  73. # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
  74. # INCLUDE_DIRS += $(shell brew --prefix)/include
  75. # LIBRARY_DIRS += $(shell brew --prefix)/lib
  76. # Uncomment to use `pkg-config` to specify OpenCV library paths.
  77. # (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
  78. # USE_PKG_CONFIG := 1
  79. BUILD_DIR := build
  80. DISTRIBUTE_DIR := distribute
  81. # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
  82. # DEBUG := 1
  83. # The ID of the GPU that 'make runtest' will use to run unit tests.
  84. TEST_GPUID := 0
  85. # enable pretty build (comment to see full commands)
  86. Q ?= @

10.編譯caffe

make -j4
編譯可能會有點慢,你可以先去幹點別的事情

  • 測試一下編譯結果
    make test
    make runtest

11.編譯pycaffe

make pycaffe -j4


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章