最近在學機器視覺和深度學習,需要安裝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