本篇博客主要用於記錄Ubuntu 14.04 64bit操作系統搭建caffe環境,目前針對的的是CPU版本;
1.安裝依賴庫
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
CUDA:如果僅僅是cpu安裝,忽略這一步;
BLAS:安裝ATLAS
sudo apt-get install libatlas-base-dev
Python:可選
2.安裝python依賴的依賴庫:
安裝gfortran,后面編譯過程中會用到
sudo apt-get install gfortran
安裝blas,Ubuntu下對應的是libopenblas,其它操作系統可能需要安裝其它版本的blas——這是個OS相關的。
sudo apt-get install libopenblas-dev
安裝lapack,Ubuntu下對應的是liblapack-dev,和OS相關。
sudo apt-get install liblapack-dev
安裝atlas,Ubuntu下對應的是libatlas-base-dev,和OS相關。
sudo apt-get install libatlas-base-dev
安裝pip
sudo apt-get install python-pip
sudo apt-get install python-dev
sudo apt-get install python-nose
sudo apt-get install g++
sudo apt-get install git
3.Ubuntu14.04安裝相關依賴庫
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
4.通過git,拉取源碼
git clone https://github.com/BVLC/caffe.git
5.安裝python依賴
cd caffe/python
for req in $(cat requirements.txt); do sudo pip install $req; done
6.編輯caffe所需的Makefile文件
cd caffe
cp Makefile.config.example Makefile.config
vim Makefile.config
主要修改這兩處
#去掉注釋
CPU_ONLY := 1
BLAS_INCLUDE := /usr/include/atlas/
7.編譯caffe
make -j4
測試編譯結果:
make test
make runtest
測試結果如下:

8.配置python
# 編譯pycaffe
make pycaffe -j4
make distribute
進入python后,直接import caffe會失敗,

在.bashrc中配置,
sudo gedit ~/.bashrc
# 我的caffe/python目錄 /home/zhb/Desktop/Work/caffe/python
export PYTHONPATH=$PYTHONPATH:/your/path/caffe/python
source ~/.bashrc

9.mnist數據測試
cd caffe
#下載mnist數據
sh data/mnist/get_mnist.sh
sh examples/mnist/create_mnist.sh
# 修改 solver_mode 為 CPU
vim examples/mnist/lenet_solver.prototxt
./examples/mnist/train_lenet.sh
執行結果如下:

10.參考鏈接
