欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ubuntu14.04安装caffe(cpu版)

程序员文章站 2022-07-06 10:39:57
...

参考:http://blog.csdn.net/u011762313/article/details/47262549

前言:

正文:

安装依赖库(一):

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
  • 可以安装OpenBLASMKL,以提升CPU性能,但是要修改caffeMakefile文件…


安装python

  • 我的Ubuntu14.04自带

  • 可使用pycaffe接口

安装opencv

----------------------------------------------------------------------------------------------------------

安装依赖库(二):

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

下载Caffe

cd ~
mkdir caffe-master
cd caffe-master/
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.0imread相关函数放到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-master/caffe
make pycaffe

c、添加~/caffe/python$PYTHONPATH

sudo gedit /etc/profile
# 末尾添加:export PYTHONPATH=/home/sine/caffe-master/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
>>>