Caffe官网
Caffe安装官方文档
Python3.5 Anaconda3 Caffe深度学习框架搭建
本文未提及的问题可能会在其中出现,请经常翻阅并仔细阅读;出现问题还是Google比较靠谱
安装过程中为了防止被墙,并且更好地看见每一项是否安装成功,我选择了一个一个地装
sudo apt-get install libprotobuf-dev
sudo apt-get install libleveldb-dev
sudo apt-get install libsnappy-dev
sudo apt-get install libopencv-dev
sudo apt-get install libhdf5-serial-dev
sudo apt-get install protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libgflags-dev
sudo apt-get install libgoogle-glog-dev
sudo apt-get install liblmdb-dev
./install_GUI.sh
进入GUI安装界面,安装(默认路径安装即可)source /opt/intel/mkl/bin/mklvars.sh intel64
Makefile.config
中设置BLAS := mkl
git clone https://github.com/BVLC/caffe.git
,推荐放在~
目录下python
文件夹,输入for req in $(cat requirements.txt); do conda install $req; done
将需要的包装上(Anaconda使用conda安装)cp Makefile.config.example Makefile.config
,因为我使用了Anaconda,而且安装的是CPU模式,所以需要修改Makefile.config
# CPU_ONLY := 1
反注释,用以设置CPU模式BLAS := mkl
,设置BLAS为MKL,然后设置BLAS_INCLUDE
、BLAS_LIB
echo export PYTHONPATH=$CAFE_ROOT/python:$PYTHONPATH
,$CAFE_ROOT
为自己的caffe所在路径,添加后需要运行source ~./bashrc
变量才能生效make all
-lboost_python3 未找到
– 设置链接sudo ln -s /usr/lib/x86_64-linux-gnu/libbost_python-py35.so.1.58.0 /usr/local/lib/libboost_python3.so
,其中/usr/lib/x86_64-linux-gnu/libbost_python-py35.so.1.58.0
要视具体情况修改GLIBCXX_3.4.21
– 输入conda install libgcc
google protobuf
– 输入conda list | grep protobuf
,将所有包用conda uninstall libprotobuf protobuf
移除。重装protobuf
,先到Github - Google protobuf下载C++
、Python
两个版本的protobuf,然后依照README安装 undefined symbol: PC
– 输入locate libreadline.so.6
,找到后复制到anaconda/lib
下TIFF
– conda remove libtiff
(不知是否可行,忘了记录了)leveldb
– conda uninstall leveldb
caffe自带了获取数据集的script,进入caffe主目录,输入./data/mnist/get_mnist.sh
,./examples/mnist/create_mnist.sh
获取
examples/mnist/
下lenet_train_test.protxt, lenet_solver.prototxt, train_lenet.sh
三个文件,简单的把路径设置好就可以了,需要注意这里不能用~
作为/home/user
的路径,必须把绝对路径完完整整地写上去./train_lenet.sh
...
I0922 15:04:22.516085 2727 solver.cpp:310] Iteration 10000, loss = 0.00184795
I0922 15:04:22.516126 2727 solver.cpp:330] Iteration 10000, Testing net (#0)
I0922 15:04:24.965847 2730 data_layer.cpp:73] Restarting data prefetching from start.
I0922 15:04:25.071223 2727 solver.cpp:397] Test net output #0: accuracy = 0.9919
I0922 15:04:25.071271 2727 solver.cpp:397] Test net output #1: loss = 0.0264297 (* 1 = 0.0264297 loss)
I0922 15:04:25.071283 2727 solver.cpp:315] Optimization Done.
I0922 15:04:25.071291 2727 caffe.cpp:259] Optimization Done.
make -j n
加快速度,n替换为处理器个数make
时候会出现非常多奇奇怪怪的错误,细想一下还是跟Anaconda3
有很大关系,所以如果有怎么也无法解决的问题的时候,可以尝试使用conda uninstall
去把Anaconda里面的包卸载了。make
,make test
,make runtest
的;整个过程下来也只要手动编译protobuf而已。LD_LIBRARY_PATH
的变化,但是整个安装结束后是这样的export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=~/caffe/python/caffe:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
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 layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# 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 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 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_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := mkl
# 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/intel/mkl/include
BLAS_LIB := /opt/intel/mkl/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 := /usr/local
# 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 := $(HOME)/anaconda3
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python3.6m \
$(ANACONDA_HOME)/lib/python3.6/site-packages/numpy/core/include
# Uncomment to use Python 3 (default is Python 2)
PYTHON_LIBRARIES := boost_python3 python3.6m
# 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/lib
PYTHON_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 /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
# 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
# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1
# 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 := 1
# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_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 ?= @