Ubuntu16.04+Anaconda+caffe(Only

2017-03-31  本文已影响0人  Dong_Chen

http://hmybmny.com/2016/10/install-caffe-on-ubuntu-16-dot-04-with-gpu/
序言:作者使用的是Ubuntu16.04+Anaconda+caffe(Only CPU),自己首先在win10下面安装caffe。好不容易成功,发现需要使用的demo是在ubuntu下面运行的,后来又琢磨啦好久,走过很多弯路,终于安装完成。
CUDA:
OpenCV:
Anaconda:
测试caffe:

1:Anaconda的安装

作者使用的是IDE 是Pycharm,以下为pycharm的默认设置
  1. 打开pycharm,依次点击 file->Settings(如果以后想所有项目都用anaconda python解释器就点击Default settings) - >Project: xx - >Project Interpreter
  2. 点击小齿轮,点击弹出来的add local

2:caffe的安装

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 libgflags-dev libgoogle-glog-dev liblmdb-dev 
sudo apt-get install libatlas-base-dev
```
- 3.下载Caffe
使用[Git](http://lib.csdn.net/base/git)直接下载Caffe非常简单,或者去[https://github.com/BVLC/caffe](https://github.com/BVLC/caffe)下载
`git clone git://github.com/BVLC/caffe.git`
切换到caffe的目录:`cd caffe`
- 4.打开Makefile.config。
将下面代码修改成:
```
# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1       ##注释去掉即可
```
将下面代码修改成: 
大致做的事情就是添加anaconda的python路径,注释掉系统本身自带的python路径。
```
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
#PYTHON_INCLUDE := /usr/include/python2.7 \              ###注释掉
#                /usr/lib/python2.7/dist-packages/numpy/core/include
```
```
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := $(usr/local)/anaconda2             ##取消注释,并且修改(XXX)内为自己anaconda的安装路径
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \        ##取消注释
$(ANACONDA_HOME)/include/python2.7 \
$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
```

```
# Uncomment to use Python 3 (default is Python 2)                   
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \              ##注释掉系统自带的
#                /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
#PYTHON_LIB := /usr/lib                                        ##注释掉系统自带的                  
PYTHON_LIB := $(ANACONDA_HOME)/lib                ##取消注释
```

- 5.接下来,Make Caffe:
```
make all -j8
make test -j8
make runtest -j8
```
作者在此处出现如下错误:
```
In file included from src/caffe/util/hdf5.cpp:1:0:
./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: 没有那个文件或目录
compilation terminated.
Makefile:581: recipe for target '.build_release/src/caffe/util/hdf5.o' failed
make: *** [.build_release/src/caffe/util/hdf5.o] Error 1
```
解决方案为:http://blog.csdn.net/xiaxiazls/article/details/52039473
修改Makefile.config为:
```
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include\              
                                 /usr/include/hdf5/serial/         ##添加
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial         
```
修改Makefile为(caffe文件里面,与上者区分开):
```
ifneq ($(CPU_ONLY), 1)
INCLUDE_DIRS += $(CUDA_INCLUDE_DIR)
LIBRARY_DIRS += $(CUDA_LIB_DIR)
LIBRARIES := cudart cublas curand
endif
##修改下面代码,对照添加上去
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial         
```
问题:
```
/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory
```
解决方案:
```
make clean
export CPLUS_INCLUDE_PATH=/usr/include/python2.7
make all -j8```
原因:
> python路径都改为了anaconda的路径,但是CPLUS的path没有设置,系统中我也没把aneconda设置成默认的python导致的.

错误:
```
In file included from src/caffe/util/signal_handler.cpp:7:0:
./include/caffe/util/signal_handler.h:4:34: fatal error: caffe/proto/caffe.pb.h: 没有那个文件或目录
#include “caffe/proto/caffe.pb.h” 
```
解决方案:
`sudo apt-get install –no-install-recommends libboost-all-dev`
(这个命令在安装依赖库的时候,不能漏了)

问题:
`.build_release/src/caffe/proto/caffe.pb.h:22:35: fatal error: google/protobuf/arena.h: 没有那个文件或目录
`
解决方案:

重新
```
make clean
make all -j8
make test -j8
make runtest -j8
```
出现运行最后一项后出现如下界面,表示安装完成。
![](https://img.haomeiwen.com/i4722717/5a21fbaaa3f22290.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)运行成功画面

- 配置pycaffe:
安装依赖项:

- 测试caffe

参考教程:
http://blog.csdn.net/sinat_23137713/article/details/53018104
http://blog.csdn.net/u010402483/article/details/51506616
http://blog.csdn.net/firethelife/article/details/51926754
 http://blog.csdn.net/xiaxiazls/article/details/52039473
上一篇下一篇

猜你喜欢

热点阅读