Installing Caffe+pycaffe on Ubuntu (CPU-ONLY)

系统运维 waitig 541℃ 百度已收录 0评论

转载请注明来源:http://blog.csdn.net/greenlight_74110/article/details/78568661

先移除anaconda:

sudo rm -rf ~/anaconda2

安装boost:

sudo apt-get install -y --no-install-recommends libboost-all-dev

安装其它依赖:

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

clone工程:

git clone https://github.com/BVLC/caffe
cd caffe
cp Makefile.config.example Makefile.config

python准备:

sudo pip install scikit-image protobuf
cd python
for req in $(cat requirements.txt); do sudo pip install $req; done

配置Makefile.config:

cd ..
sudo vim Makefile.config

# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1
...
# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3
...
# ANACONDA_HOME := $(HOME)/anaconda2
...
# PYTHON_LIB := $(ANACONDA_HOME)/lib

解决hdf5.so的问题见这里

开始编译:

make all
make test
make runtest

编译python层:

make pycaffe

如果报arrayobject.h的错,在Makefile.config中作如下更改:

PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include

将pycaffe的path加入到环境变量:

sudo vim ~/.bashrc

export PYTHONPATH=$HOME/Downloads/caffe/python:$PYTHONPATH

刷新使其生效:

source ~/.bashrc

现在可以使用啦:

python
>>> import caffe
>>>

试一试官方自带的例子吧:

cd ~/path/to/your/caffe
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh

进行训练之前要修改一下prototxt文件,换成CPU训练模式:

vim examples/mnist/lenet_solver.prototxt

#最后一行的GPU改成CPU

开始训练:

./examples/mnist/train_lenet.sh

接下来就是等待训练的完成啦!~


本文由【waitig】发表在等英博客
本文固定链接:Installing Caffe+pycaffe on Ubuntu (CPU-ONLY)
欢迎关注本站官方公众号,每日都有干货分享!
等英博客官方公众号
点赞 (0)分享 (0)