ubuntu 16.04
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
sudo apt-get install libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
git clone https://github.com/BVLC/caffe
cd caffe/
cp Makefile.config.example Makefile.config
我只要CPU功能,不开GPU
CPU_ONLY := 1改成CPU_ONLY := 1
make all
make test
make runtest
错误处理
/usr/include/hdf5.h:24:22: fatal error: H5public.h: 没有那个文件或目录
修改Makefile
INCLUDE_DIRS += $(BUILD_INCLUDE_DIR) ./src ./include
改成
INCLUDE_DIRS += $(BUILD_INCLUDE_DIR) ./src ./include /usr/include/hdf5/serial
/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5
Makefile
LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG)
改成
LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) -L/usr/lib/x86_64-linux-gnu/hdf5/serial/ $(PKG_CONFIG)
在安装了所有的库后,还是编译不过,需要确认下gcc,g++版本是不是5以上,另外源码编译安装protobuf
CXX/LD -o .build_debug/tools/upgrade_net_proto_text.bin
.build_debug/lib/libcaffe.so:对‘google::protobuf::Message::InitializationErrorString() const’未定义的引用
.build_debug/lib/libcaffe.so:对‘cblas_sgemv’未定义的引用
.build_debug/lib/libcaffe.so:对‘cblas_dgemm’未定义的引用
.build_debug/lib/libcaffe.so:对‘google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)’未定义的引用
.build_debug/lib/libcaffe.so:对‘cblas_sscal’未定义的引用
.build_debug/lib/libcaffe.so:对‘cblas_dgemv’未定义的引用
.build_debug/lib/libcaffe.so:对‘google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::string const&, unsigned char*)’未定义的引用
.build_debug/lib/libcaffe.so:对‘cv::imread(std::string const&, int)’未定义的引用
.build_debug/lib/libcaffe.so:对‘cblas_dcopy’未定义的引用
.build_debug/lib/libcaffe.so:对‘google::protobuf::DescriptorPool::FindFileByName(std::string const&) const’未定义的引用
.build_debug/lib/libcaffe.so:对‘google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::string*)’未定义的引用
.build_debug/lib/libcaffe.so:对‘cblas_saxpy’未定义的引用
.build_debug/lib/libcaffe.so:对‘cblas_ddot’未定义的引用
.build_debug/lib/libcaffe.so:对‘google::protobuf::internal::StringTypeHandlerBase::Delete(std::string*)’未定义的引用
.build_debug/lib/libcaffe.so:对‘google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::string const&))’未定义的引用
.build_debug/lib/libcaffe.so:对‘leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)’未定义的引用
.build_debug/lib/libcaffe.so:对‘cblas_sgemm’未定义的引用
查看gcc g++版本号,如果在5.0以下就升级它们
ll /usr/bin/g++
lrwxrwxrwx 1 root root 21 7月 11 2017 /usr/bin/g++ -> /etc/alternatives/g++*
g++ --version
g++ (Ubuntu 4.8.5-4ubuntu2) 4.8.5
我系统下面有g++ 4.8与5.4.0,只要链接到5.4.0就行,gcc已经是5.4.0了,不处理
sudo rm /etc/alternatives/g++
sudo ln -s /usr/bin/g++-5 /etc/alternatives/g++
ll /etc/alternatives/g++
lrwxrwxrwx 1 root root 14 4月 25 11:47 /etc/alternatives/g++ -> /usr/bin/g++-5*
g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
请删除系统的protobuf从源码下载安装
sudo apt remove libprotobuf-dev
然后下源码重新编译protobuf
git clone https://github.com/google/protobuf
cd protobuf/
./autogen.sh
./configure --prefix=/usr
make
sudo make install
在执行caffe示例中siamese模型的时候出错
./examples/siamese/train_mnist_siamese.sh
I0425 15:01:12.400749 12592 caffe.cpp:204] Using GPUs 0
F0425 15:01:12.400856 12592 common.cpp:66] Cannot use GPU in CPU-only Caffe: check mode.
*** Check failure stack trace: ***
@ 0x7f9ab80e25cd google::LogMessage::Fail()
@ 0x7f9ab80e4433 google::LogMessage::SendToLog()
@ 0x7f9ab80e215b google::LogMessage::Flush()
@ 0x7f9ab80e4e1e google::LogMessageFatal::~LogMessageFatal()
@ 0x7f9ab872887b caffe::Caffe::SetDevice()
@ 0x41d7ec train()
@ 0x41fd87 main
@ 0x7f9ab6ee8830 __libc_start_main
@ 0x41c859 _start
@ (nil) (unknown)
Aborted (core dumped)
应为我没开GPU功能,所以得改配置
examples/siamese/mnist_siamese_solver.prototxt
solver_mode: GPU
改成
solver_mode: CPU
作者: 帅得不敢出门