[关闭]
@hanxiaoyang 2016-10-26T09:29:23.000000Z 字数 4935 阅读 13772

linux(ubuntu)下的caffe编译安装

caffe


0.关于caffe(by@寒小阳)

caffe是深度学习在图像领域广泛使用的框架,其model zoo有大量的预训练好的模型提供使用。图像相关应用会大量使用到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
编译可能会有点慢,你可以先去干点别的事情

11.编译pycaffe

make pycaffe -j4

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注