Ubuntu18.04+Caffe

1、配置依赖

$ 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

2、ATLAS( BLAS )

$ sudo apt-get install libatlas-base-dev

3、Opencv

详细请见:https://blog.csdn.net/qq_33838170/article/details/83464525

4、Protobuf

$ git clone https://github.com/google/protobuf
$ sudo apt-get remove libprotobuf-dev
$ 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

卸载

which protoc 
rm /usr/local/bin/protoc

然后删除文件夹

5、glog

$ wget https://github.com/google/glog/archive/v0.3.3.tar.gz
$ tar zxvf v0.3.3.tar.gz
$ cd glog-0.3.3
$ ./configure
$ make -j8  
$ sudo make install -j8

6、gflags

$ wget https://github.com/schuhschuh/gflags/archive/master.zip
$ unzip master.zip
$ cd gflags-master
$ mkdir build && cd build
$ export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
$ make -j8
$ sudo make install -j8

7、 lmdb

$ git clone https://github.com/LMDB/lmdb
$ cd lmdb/libraries/liblmdb
$ make -j8
$ sudo make install -j8

8、Makefile.config配置

$ git clone https://github.com/BVLC/caffe
$ cd caffe
$ cp Makefile.config.example Makefile.config
$ sudo gedit Makefile.config

根据需要修改相关内容(去掉注释)

#CPU_ONLY := 1
#USE_CUDNN := 1
#OPENCV_VERSION := 3
#WITH_PYTHON_LAYER := 1

为避免发生hdf5相关错误,在Ubuntu16.04及以上版本需要将

#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

#CUSTOM_CXX := g+±4.8

9、Makefile配置

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

替换为

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

10、编译

$ make all -j8//-j8是多核编译加快速度
$ make test -j8
$ make runtest -j8

11、愉快的debug

1、nvcc fatal : Unsupported gpu architecture ‘compute_20’

解决办法:

在 Makefile.config中去掉以下两行(由于是9以上版本、仔细看Makefile)

-gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \

2、/usr/bin/ld: cannot find -lopencv_imgcodecs(或其他类似)

解决办法:

在Makefile最后加上
LIBRARIES += glog gflags protobuf leveldb snappy
lmdb boost_system boost_filesystem hdf5_hl hdf5 m
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio
保存
make clean 再编译

3、collect2: error: ld returned 1 exit status

解决办法:

/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.


以上是原始的编译方式在Ubuntu18.04上的作死尝试,其实在Ubuntu18.04上可以用命令行安装预编译的CAFFE: sudo apt-get install caffe-cpu/cafe-cuda/caffedoc/caffe-tools-cpu/caffe-tools-cuda
caffeine 好像是一个java的高性能缓存库
只在caffedoc目录下找到了包括model、sample在内的相关文件,caffecpu内没有。
命令行运行caffe device_query test time train等命令出现错误:Check failed: FLAGS_model.size() > 0(0 vs. 0) Need a model definition to time. 暂未处理

猜你喜欢

转载自blog.csdn.net/qq_33838170/article/details/83465313
今日推荐