前言
segnet语义分割模型是一种经典的Encoder-Decoder的全卷积网络模型。github上有比较多使用pytorch框架来该模型的实现。而论文作者Alex是基于caffe框架来对它进行复现。 、
我们这里考虑是后者,其对应的github地址为https://github.com/alexgkendall/caffe-segnet
代码下载及准备
首先下载代码,如下图所示。 网络不好时,容易下载失败。有时明明直接下载zip包成功,但是解压缩失败。总之多试几次。
2)依赖包的安装
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev
编译过程
1)在caffe-segnet根目录下, cp Makefile.config.example Makefile.config 然后对Makefile.config进行修改,如下所示。
2)编译遇到的第一个问题:protoc: Command not found 如下图所示
解决方法:需要安装protoc-c
sudo apt-get install protobuf-c-compiler protobuf-compiler
3)gflags.h找不到的错误,如下所示
./include/caffe/common.hpp:5:10: fatal error: gflags/gflags.h: 没有那个文件或目录
#include <gflags/gflags.h>
解决思路:
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
4)cblas.h找不到的错误
./include/caffe/util/mkl_alternate.hpp:11:10: fatal error: cblas.h: 没有那个文件或目录
#include <cblas.h>
解决方法:
sudo apt-get install libblas-dev
5)找不到hdf5.h文件
./include/caffe/data_layers.hpp:9:10: fatal error: hdf5.h: 没有那个文件或目录
#include "hdf5.h"
解决方法:
sudo apt-get install libhdf5-serial-dev
6)不支持 compuer_20的CUDA架构
nvcc fatal : Unsupported gpu architecture 'compute_20'
Makefile:539: recipe for target '.build_release/cuda/src/caffe/layers/mvn_layer.o' failed
解决办法,如上面截图所示,就是将Makefile.confg中的computer_20,computer_21给注掉。
7)链接时找不到 atlas库
LD -o .build_release/lib/libcaffe.so
/usr/bin/ld: 找不到 -lcblas
/usr/bin/ld: 找不到 -latlas
解决办法:
sudo apt-get install libatlas-base-dev
8)最后一个链接错误是,找不到imread之类的opencv APIs.
build_release/lib/libcaffe.so:对‘cv::imread(cv::String const&, int)’未定义的引用
解决方法是 在Makefile里面 将libopencv_imgcodecs.so库链接进来
结束语
终于可以 make all -j8 以及 make pycaffe -j8成功了。这其实就是在一个比较干净的ubuntu18.04上面想要编译caffe代码通过的程。