目录:
$ lspci | grep -i nvidia
,发现没有nvidia显卡,所以只能暂时放弃Gpu,改用Cpu了。$ 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
$ sudo apt-get install libatlas-base-dev
$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
$ cd ~
$ git clone git://github.com/BVLC/caffe.git
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
#include
否则会出现”CV_BGR2GRAY”的错误
$ cd ~/caffe
$ cp Makefile.config.example Makefile.config
# 修改Makefile.config文件:去掉CPU_ONLY:= 1的注释
$ make all
$ make test
$ make runtest
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
>>>
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
即可