虚拟机下装cpu版的caffe

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/include
INCLUDE_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 hdf5
LIBRARIES += 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 all
make pycaffe

测试(可选)

make test
make 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值