Ubuntu 16.04 install caffe and pycaffe

前端之家收集整理的这篇文章主要介绍了Ubuntu 16.04 install caffe and pycaffe前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

cpu_ONLY

参考官方安装教程

配置文件

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

编译安装步骤

  1. #安装依赖
  2. 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
  3. sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
  4.  
  5. #下载caffe
  6. git clone https://github.com/BVLC/caffe
  7. cd /path/to/caffe/folder
  8.  
  9. #修改配置文件
  10. make all -j $(($(nproc) + 1))
  11. make test -j $(($(nproc) + 1))
  12. make runtest -j $(($(nproc) + 1))
  13.  
  14. #安装pycaffe
  15. sudo apt-get install cython
  16. sudo apt-get install python-skimage
  17. sudo apt-get install python-pip
  18. sudo pip install protobuf
  19.  
  20. make pycaffe
  21.  
  22. #设置pycaffe
  23. export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH

问题及解决

  1. conda install libgcc
  1. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
  2. LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial

 GPU

 参考教程

猜你在找的Ubuntu相关文章