caffe_segnet的安装记录

caffe_segnet中自带caffe,但是安装完毕caffe,无法运行caffe_segnet。

对于cudnn5版本的:https://github.com/TimoSaemann/caffe-segnet-cudnn5,若不是用此版本,编译不过去

安装 Protocol Buffers:

1
2
3
4
5
6
7
8
9
10
cd ~
git clone https://github.com/google/protobuf.git
sudo apt-get install autoconf automake libtool curl make g++ unzip
cd protobuf
./autogen.sh
./configure --prefix=/usr
make
make check
sudo make install
sudo ldconfig # refresh shared library cache.

安装caffe_segnet:

1
2
cp Makefile.config.example Makefile.config
# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)

然后根据个人情况修改文件:

1.若使用cudnn,则将#USE_CUDNN := 1修改成: USE_CUDNN := 1 (就是去掉注释的‘#’号)

2.若使用的opencv版本是3的,则将#OPENCV_VERSION := 3 修改为: OPENCV_VERSION := 3

3.若要使用python来编写layer,则将#WITH_PYTHON_LAYER := 1修改为 WITH_PYTHON_LAYER := 1

4.要是你是用的anaconda的话,还需要改一些地方

这里写图片描述

把之前的PYTHON_INCLUDE加上注释,把ANACONDA_HOME以及下面的PYTHON_INCLUDE 都去掉,并且改为如下图最终的样子。

这里写图片描述

5.重要 :
# Whatever else you find you need goes here.下面的
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
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
(因为ubuntu16.04的文件包含位置发生了变化)

然后:

1
2
3
make all
make test
make runtest

添加Python:

1
2
make pycaffe
make distribute

若未执行 make distribute,则可能出现如下bug:

1
2
3
4
5
6
7
8
Traceback (most recent call last):
File "detector.py", line 29, in <module>
import caffe
File "/python/caffe/__init__.py", line 1, in <module>
from .pycaffe import Net
File "/caffe/pycaffe.py", line 6, in <module>
from ._caffe import CaffeNet
ImportError: No module named _caffe

若出现如下bug:

1
2
3
4
5
6
7
8
9
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp

python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory

compilation terminated.

Makefile:501: recipe for target 'python/caffe/_caffe.so' failed

make: *** [python/caffe/_caffe.so] Error 1

解决方法:配置Makefile.config中numpy位置,可在pycharm下查看

若出现不能import caffe,提示没有这个模块,要在~/.bashrc 文件加入,且运行程序是不加sudo:

1
export PYTHONPATH=/home/ubuntu/SegNet/caffe-segnet-cudnn5-master/python:$PYTHONPATH

若出现如下bug:

1
[ RUN ] Solver Test/2.TestInitTrainTestNets F0423 11:28:29.802130 18952 cudnn softmax_layer.cpp:15] Check failed: status == CUDNN_STATUS_SUCCESS (4 vs. 0) CUDNN_STATUS_INTERNAL_ERROR

重新编译一下cudnn

当出现问题要重新编译的时候,可以用:

1
make clean
------ 本文结束------
坚持原创技术分享,您的支持将鼓励我继续创作!

欢迎关注我的其它发布渠道