本篇博客主要用于记录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.参考链接