虚拟机下装cpu版的caffe

来源:互联网 发布:淘宝订购的应用 编辑:程序博客网 时间:2024/06/05 07:27

Ubuntu版本:Ubuntu 15.10


因为电脑显卡不行,并且在虚拟机下,只是尝试一下cpu版的caffe安装。


安装步骤:

1、先下载caffe

# sudo git clone https://github.com/BVLC/caffe.git

2、安装一系列依赖库

# sudo apt-get install libatlas-base-dev# sudo apt-get install libprotobuf-dev# sudo apt-get install libleveldb-dev# sudo apt-get install libsnappy-dev# sudo apt-get install libopencv-dev# sudo apt-get install libboost-all-dev# sudo apt-get install libhdf5-serial-dev# sudo apt-get install libgflags-dev# sudo apt-get install libgoogle-glog-dev# sudo apt-get install liblmdb-dev# sudo apt-get install protobuf-compiler

3、安装OpenCV

# cd caffe# sudo git clone https://github.com/jayrambhia/Install-OpenCV# cd Install-OpenCV/Ubuntu# sudo sh dependencies.sh# cd 2.4# sudo sh opencv2_4_10.sh

4、编译caffe

# cd ~/caffe# sudo cp Makefile.config.example Makefile.config# make all

注:make all的时候出错了


说缺少hdf5.h文件

解决方法:

1)Makefile.config文件的第85行,添加/usr/include/hdf5/serial/ 到 INCLUDE_DIRS,也就是把下面第一行代码改为第二行代码。

INCLUDE_DIRS:=$(PYTHON_INCLUDE) /usr/local/includeINCLUDE_DIRS:=$(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/


2)Makefile文件的第173行,把 hdf5_hl 和hdf5修改为hdf5_serial_hl 和 hdf5_serial,也就是把下面第一行代码改为第二行代码。

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial


修改上面的文件时需要root权限,可用sudo vi Makefile.config命令在vi环境下修改好。


还有一点:

在make all前需要编辑Makefile文件,主要是一些配置选项,有cuda和没有cuda不一样.

因为我用的cpu,需要把下面cpu_only这句uncomment,cudnn这句comment。

# cuDNN acceleration switch (uncomment to build with cuDNN).# USE_CUDNN := 1# CPU-only switch (uncomment to build without GPU support).CPU_ONLY := 1
还有这几句,都注调了。

# CUDA architecture setting: going with all of them.# For CUDA < 6.0, comment the *_50 lines for compatibility.# CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \#                 -gencode arch=compute_20,code=sm_21 \#                 -gencode arch=compute_30,code=sm_30 \#                 -gencode arch=compute_35,code=sm_35 \#                 -gencode arch=compute_50,code=sm_50 \#                 -gencode arch=compute_50,code=compute_50

大致就这两个错误解决就可以sudo make all 成功了。

make allmake pycaffe

测试(可选)

make testmake runtest

如果出现一系列的 run ok,应该是装好了。


5、测试mnist数据集

# cd ~/caffe# sudo sh data/mnist/get_mnist.sh# sudo sh examples/mnist/create_mnist.sh
运行这一步中第三句出了个错误,说convert_mnist_data.bin:not found,我找了下convert_mnist_data这个名字,只找到一个cpp文件,最后是重新make all了一遍好了。

如果有GPU可以运行下一步,因为我只有cpu,所以还要改点东西。

# sudo vi examples/mnist/lenet_solver.prototxt
将最后一行的solver_mode:GPU改为solver_mode:CPU



然后执行下面的命令测试

sudo sh ./examples/mnist/train_lenet.sh
然后等着看结果


最终的精度达到了0.9914,很高的精度


参考资源

1)http://www.cnblogs.com/denny402/p/5067265.html

2)http://blog.csdn.net/xue_wenyuan/article/details/52037121

3)http://suanfazu.com/t/ubuntu-14-04-caffe/447

4)http://blog.csdn.net/hongye000000/article/details/51043913

5)http://coldmooon.github.io/2015/08/03/caffe_install/

6)https://gist.github.com/bearpaw/c38ef18ec45ba6548ec0



0 0