1、下载caffe源码https://github.com/alexgkendall/caffe-segnet。使用caffe-segnet-segnet-cleaned.zip压缩包解压后改为caffe-segnet。
2、进入到caffe-segnet下,运行
cp Makefile.config.example Makefile.config
之后, 修改Makefile.config,注意将WITH_PYTHON_LAYER := 1前的注释去掉。
cp Makefile.config.example Makefile.config
之后在终端依次运行make all,make test,make runtest. 如果运行当中如下错误:
CXX/LD -o .build_release/tools/convert_imageset.bin .build_release/lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)’ .build_release/lib/libcaffe.so: undefined reference tocv::imencode(cv::String const&, cv::_InputArray const&, std::vector >&, std::vector > const&)’ .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)’ collect2: error: ld returned 1 exit status make: * [.build_release/tools/convert_imageset.bin] Error 1
查看opencv是否安装:
$ pkg-config --modversion opencv
如果输出opencv的版本则
应该是
opencv_imgcodecs
链接的问题,比较有效的解决方案是,把opencv需要的lib添加到
Makefile
文件中,找到
LIBRARIES
(在
PYTHON_LIBRARIES := boost_python python2.7
前一行)并修改为:
LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system hdf5_hl hdf5 m\
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
每次需要重新编译的过程中,首先需要清除掉以往编译的结果:
$ make clean
之后在终端依次运行make all,make test,make runtest.(或者
make
all、
make
pycaffe、
make
test)。
若不出问题,这样segnet的caffe环境就搭建起来了。