ubuntu14.04或者ubuntu16.04 配置caffe

1.安装了cuda和cudnn,参考链接opencv

ubuntu14.04与ubuntu16.04两者的安装仅有小部分区别。

安装基本库:

sudo apt-get install libatlas-base-dev
sudo apt-get install libgoogle-glog-dev
sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install -y --no-install-recommends libboost-all-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev

2. 获取caffe:

cd
git clone https://github.com/BVLC/caffe.git

3.安装需要的依赖包:

cd caffe/python
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy 

安装requirement里面的包

sudo su
for req in $(cat requirements.txt); do pip install $req; done

4.修改配置文件

cd ~/caffe
cp Makefile.config.example Makefile.config
gedit Makefile.config
  1. 使用cuDNN # USE_CUDNN := 1 ,这里去掉#,取消注释

  2. 使用opencv3,#OPENCV_VERSION := 0 修改为: OPENCV_VERSION := 3

  3. 若要使用python来编写layer,则 #WITH_PYTHON_LAYER := 1,前面的#号去掉。

  4. 将# Whatever else you find you need goes here. 下面的

1 INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
2 LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

修改为

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  

如果你的不是cuda8.0还需要将compute那一部分改一改:文件中的要求改就好了。

5.修改makefile文件:

打开makefile文件,做如下修改:

NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

替换为:

NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

如果你是ubuntu16.04那么你需要修改以下路径,如果是14.04则不需要:

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5

修改为:

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

LIBRARIES += boost_thread stdc++修改为:

LIBRARIES += boost_thread stdc++ boost_regex

6.编辑/usr/local/cuda/include/host_config.h,将其中的第115行注释掉:

#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!

改为:

//#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!

7.编译:

make all –j8
make test –j8
make runtest –j8

8.编译pycaffe

在caffe根目录的python文件夹下,有一个requirements.txt的清单文件,上面列出了需要的依赖库,按照这个清单安装就可以了。

在安装scipy库的时候,需要fortran编译器(gfortran),如果没有这个编译器就会报错,因此,我们可以先安装一下。

首先回到caffe的根目录,然后执行安装代码:

cd ~/caffe
sudo apt-get install gfortran
cd ./python
sudo su
for req in $(cat requirements.txt); do pip install $req; done

安装完成以后,再次回到caffe根目录我们可以执行:

cd ..
cd caffe
sudo pip install -r python/requirements.txt

就会看到,安装成功的,都会显示Requirement already satisfied, 没有安装成功的,会继续安装。

编译python接口:

make pycaffe  -j8

配置环境变量,以便python调用:

sudo gedit ~/.bashrc

export PYTHONPATH=/home/caffe/python:$PYTHONPATH添加到文件中

source ~/.bashrc

之后进入caffe/python目录下:

报错解决:

1.make: protoc:命令未找到

sudo apt-get install protobuf-c-compiler protobuf-compiler

2.报错:./include/caffe/util/db_leveldb.hpp:7:24: fatal error: leveldb/db.h: 没有那个文件或目录

sudo apt-get install libleveldb-dev

3.报错:./include/caffe/util/db_lmdb.hpp:8:18: fatal error: lmdb.h: 没有那个文件或目录#include "lmdb.h"

sudo apt install liblmdb-dev

4.报错:/usr/bin/ld: cannot find -hdf5_serial_hl

之前报这个错,最后发现ubuntu14.04不用修改下面这句

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5

参考:

https://blog.csdn.net/luoshenzhisi/article/details/44780389

https://blog.csdn.net/weixin_42652125/article/details/81202540

https://www.cnblogs.com/go-better/p/7161006.html

https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-Installation-Guide

猜你喜欢

转载自blog.csdn.net/weixin_39059031/article/details/84823717
今日推荐