最近在学机器视觉和深度学习,需要安装caffe。苦于之前用的fedora安装依赖各种安装不上,索性下载了最新版ubuntu16.04来安装caffe。不过由于系统比较新,有些依赖库名字已经变了,安装的时候需要修改Makefile和配置文件。为了让其他人少走弯路,总结了下自己的经验。
1.下载caffe源码
git clone htts://github.com/BVLC/caffe.git
2.安装依赖库
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler libopenblas-dev
3.修改Makefile
cd caffe
cp Makefile.config.example Makefile.config
修改Makefile.config如下几个配置:
USE_CPU := 1
USE_OPENCV := 1
USE_LMDB := 1
BLAS := open
WITH_PYTHON_LAYER := 1
修改Makefile如下几个地方:
diff --git a/Makefile b/Makefile
index 2489406..5d56738 100644
--- a/Makefile
+++ b/Makefile
@@ -171,14 +171,14 @@ ifneq ("$(wildcard $(CUDA_DIR)/lib64)","")
endif
CUDA_LIB_DIR += $(CUDA_DIR)/lib
-INCLUDE_DIRS += $(BUILD_INCLUDE_DIR) ./src ./include
+INCLUDE_DIRS += $(BUILD_INCLUDE_DIR) ./src ./include /usr/include/hdf5/serial
ifneq ($(CPU_ONLY), 1)
INCLUDE_DIRS += $(CUDA_INCLUDE_DIR)
LIBRARY_DIRS += $(CUDA_LIB_DIR)
LIBRARIES := cudart cublas curand
endif
-LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
+LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
# handle IO dependencies
USE_LEVELDB ?= 1
将减号(-)那行用加号(+)那行替换掉,不要带第一个加号
4.编译
make all
make test
make runtest
5.编译python库
sudo apt-get install python-pip python-dev build-essential
sudo pip install --upgrade pip
sudo pip install -r python/requirements.txt
make pycaffe
6.安装并运行notebook
sudo apt-get install ipython-notebook python-sympy
sudo pip install jupyter
mkdir notebook
cd notebook
ipython notebook
7.运行caffe
cd caffe
./data/mnist/get_mnist.sh
./example/mnist/create_mnist.sh
./example/mnist/train_lenet.sh
不过执行 train_lenet.sh 的时候始终过不去,貌似是 tools/caffe.cpp 的问题,没有正确处理CPU模式和GPU模式
下面这篇文章里有比较详细的介绍
http://www.open-open.com/lib/view/open1421995285109.html