您的位置:首页 > Web前端

【Caffe安装】Ubuntu14.04上Caffe配置安装(Only CPU)

2016-07-29 14:28 573 查看
常说天作孽犹可违,人作孽不可活啊,那为了毕设,我就是作死啊。没办法自己从三月份辞掉实习开始断断续续学习深度学习,才明白入坑虽浅,基情不断啊。为了能够完成毕设,便选了Caffe,也到处都是坑啊。没办法,为了祭奠我那糟糕透顶的记忆脑细胞,用我这糟糕的文笔稍微记录一下吧。

首先想吐槽一下,我的电脑没有Nvidia,没有Nvidia,没有Nvidia,重要的事情说三篇。在这上面就耽误了好几天。

安装依赖包 

1.安装protobuf,leveldb,snappy,opencv,hdf5, protobuf compiler andboost:
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
1
2
3

2.安装gflags,glogs ,lmdb andatlas.
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install libatlas-base-dev
1
2

下载Caffe 

使用git直接下载Caffe非常简单,或者去https://github.com/BVLC/caffe下载
git clone git://github.com/BVLC/caffe.git
1

编译Caffe 

1.切换到Caffe所在目录
cp Makefile.config.example Makefile.config
1

2.配置Makefile.config

1)CPU_ONLY := 1

2)配置一些引用文件(增加部分主要是解决新版本下,HDF5的路径问题)
1)INCLUDE_DIRS := $(PYTHON_INCLUDE)
/usr/local/include
/usr/lib/x86_64-linux-gnu/hdf5/serial/include

2)LIBRARY_DIRS := $(PYTHON_LIB)
/usr/local/lib
/usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
3)BLAS := atlas
计算能力 mkl > openlas >atlas
1
2
3
4
5
6
7
8
9

3.Make Caffe
make all -j8
make test -j8
make runtest -j8
1
2
3

4.编译成功,否则执行 make clean 多执行以下,否则多google吧

编译python接口 

1.Caffe拥有python\C++\shell接口,在Caffe使用python特别方便,在实例中都有接口的说明。

1)确保pip已经安装
sudo apt-get install python-pip
1

2)新建shell文件并执行安装依赖
for req in $(cat requirements.txt); do pip install $req; done
1

3)编译python接口
make pycaffe
1

当出现下面错误的时候修改
fatal error: numpy/arrayobject.h: No such file or directory.
1
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include This is where our error is. So by changing this line to:

PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include
# Our problem is gone.
1
2
3
4
5
6

2.运行python结构
import sys
sys.path.append("~/Documents/caffe/python")
'''
import caffe If the last import caffe doesn't pop out any error, congratulations, now you can use python to play with caffe!
'''
1
2
3
4
5

在Mnist运行Lenet 

1.获取数据源
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh
1
2

2.因为是CPU运行,所以修改在examples文件下的Mnist下的lenet_solver.prototxt中的solver_mode:CPU
solver_mode: CPU
1

3.训练模型
./examples/mnist/train_lenet.sh
1

终于写完了,该吃饭去了。

参考

[1]http://m.blog.csdn.net/article/details?id=50179759 GPU+Caffe安装

[2]http://sunshineatnoon.github.io/How-to-install-caffe/ CPU
+ Caffe安装

[3]https://github.com/BVLC/caffe/wiki

[4]http://www.cnblogs.com/denny402/p/5067265.html GPU+Caffe安装
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: