Ubuntu14.04 安装Caffe(仅CPU)

34 篇文章 0 订阅
29 篇文章 2 订阅

目录:

前言:


GPU版本


正文:

安装依赖库(一):

$ 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

安装BLAS:

$ sudo apt-get install libatlas-base-dev
  • 可以安装OpenBLAS 或 MKL,以提升CPU性能,但是要修改caffe中Makefile文件…

安装python

  • 我的Ubuntu14.04自带
  • 可使用pycaffe接口

安装matlab


安装opencv


安装依赖库(二):

$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

下载Caffe:

$ cd ~
$ git clone git://github.com/BVLC/caffe.git

如果安装的是opencv3.0:

a、修改Makefile,在

LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs

处加入后面的opencv_imgcodecs,因为opencv3.0.0把imread相关函数放到imgcodecs.lib中了(原来是imgproc.lib)

b、修改caffe/examples/cpp_classification/classification.cpp文件,加入:

#include <opencv2/imgproc/types_c.h>
#include <opencv2/objdetect/objdetect_c.h>

否则会出现”CV_BGR2GRAY”的错误


编译Caffe:

$ cd ~/caffe
$ cp Makefile.config.example Makefile.config
# 修改Makefile.config文件:去掉CPU_ONLY:= 1的注释
$ make all
$ make test
$ make runtest

配置pycaffe:

a、安装依赖库:

$ sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags Cython ipython
$ sudo apt-get install protobuf-c-compiler protobuf-compiler

b、编译:

$ cd ~/caffe
$ make pycaffe

c、添加~/caffe/python到$PYTHONPATH:

$ sudo gedit /etc/profile
# 末尾添加: export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
# 用完整路径,不要用~
$ source /etc/profile # 使之生效

d、测试是否可以引用:

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>> 

配置matcaffe:

a、gcc降级(Ubuntu14.04自带的gcc版本是4.8,MATLAB2014a支持的最高版本为4.7x。因此,需要安装gcc4.7,并给gcc降级):
详见Ubuntu中update-alternatives命令(版本切换)

sudo apt-get install gcc-4.7 g++-4.7 g++-4.7-multilib gcc-4.7-multilib
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.7 100 
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 100 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.7 100
sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.8 50

# 验证gcc默认版本:
$ gcc -v 

b、编译:

$ cd ~/caffe
# 修改Makefile.config文件,MATLAB_DIR := /usr/local/MATLAB/R2014a
$ make matcaffe

c、添加工作空间:

$ sudo matlab -nodesktop -nosplash
>>> addpath ~/caffe/matlab
>>> savepath

即可

  • 2
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 18
    评论
评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值