Caffe學習-Caffe編譯常見錯誤總結及解決方法

1. 引言

一如Caffe深似海,從此Torch是路人~

Caffe學習第一步,搭建Caffe環境,編譯一個基礎的caffe~

但是很多深度學習小白,在這第一步一走就是一個周甚至更久,尤其是caffe-GPU版本的編譯,本文主要記錄一些常見caffe編譯錯誤,曾經編譯無數caffe,每一次,最後成功的那一刻,幾乎都留下了熱淚…

持續爲大家採坑,有需要請移步我的其它文章~
caffe-CPU版安裝:
Caffe安裝教程:Ubuntu16.04(CPU)
caffe-GPU版安裝:
Ubuntu16.04 Caffe(GPU版)詳細安裝教程

2. caffe編譯常見錯誤及解決方案

問題1:編譯選項問題

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

/usr/include/c++/4.9/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.
#error This file requires compiler and library support for the
/usr/local/include/google/protobuf/arena.h:324:36: note: template argument deduction/substitution failed:
Makefile:600: recipe for target ‘.build_release/src/caffe/proto/caffe.pb.o’ failed
make: *** [.build_release/src/caffe/proto/caffe.pb.o] Error 1

解決方法
方法1:
這是由於沒有在makefile文件中導入c++11版本,因此打開makefile後,在COMMON_FLAGS後加入-std=c++11 #update by holobo語句,如下:
在這裏插入圖片描述
方法2:

在Makefile文件中找到:
##############################
#configure build
##############################
找到:
#Linux
添加:CXXFLAGS += -std=c++11

安裝上面的方法一開始沒報錯,但過了一段時間後還是報同樣的錯誤,再進一步如下修改,打開Makefile文件,給CXXFLAGS、NVCCFLAGS、LINKFLAGS都使用-std=c++11標準編譯:

CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS) 
改爲:
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11 
 
 
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
改爲:
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)  -std=c++11
 
 
LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
改爲:
LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11

問題2:numpy路徑問題

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

解決方法

由於numpy路徑在Makefile.config文件中寫錯,因此更改,重新編譯即可
在這裏插入圖片描述

問題3:CUDA版本問題

NVCC src/caffe/solvers/adagrad_solver.cu
nvcc fatal : Unsupported gpu architecture ‘compute_20’
NVCC src/caffe/solvers/sgd_solver.cu
nvcc fatal : Unsupported gpu architecture ‘compute_20’
Makefile:607: recipe for target ‘.build_release/cuda/src/caffe/solvers/rmsprop_solver.o’ failed

原因是不支持GPU架構’compute_20’,在Makefile.config裏面的找到

CUDA_ARCH := -gencode arch=compute_20,code=sm_20
                  -gencode arch=compute_20,code=sm_21 \
                  -gencode arch=compute_30,code=sm_30 \
                  -gencode arch=compute_35,code=sm_35 \
                  -gencode arch=compute_50,code=sm_50 \
                  -gencode arch=compute_52,code=sm_52 \
                  -gencode arch=compute_60,code=sm_60 \
                  -gencode arch=compute_61,code=sm_61 \
                  -gencode arch=compute_61,code=compute_61

把前面compute_20相關的那2行刪除
-gencode arch=compute_20,code=sm_20
-gencode arch=compute_20,code=sm_21

問題4: g++版本問題

.build_release/lib/libcaffe.so:對‘leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)’未定義的引用
.build_release/lib/libcaffe.so:對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::Status::ToString() const’未定義的引用
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target ‘.build_release/tools/upgrade_solver_proto_text.bin’ failed
make: *** [.build_release/tools/upgrade_solver_proto_text.bin] Error 1
make: *** 正在等待未完成的任務…

先查看g++版本:

gcc --version     # 或 g++ --version

gcc (Ubuntu 4.9.3-13ubuntu2) 4.9.3
Copyright © 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

發現我的是4.9.3版本,需要升級gcc版本。查看我Ubuntu系統發現裏面已經存在更高級的5版本,就不用再安裝了,直接強制軟鏈接一下即可:
在這裏插入圖片描述

sudo ln -s /usr/bin/gcc-5 /usr/bin/gcc -f
sudo ln -s /usr/bin/g++-5 /usr/bin/g++ -f

升級G++版本,重新編譯即可。

問題5:Python版本問題

如果在Makefile.config文件裏面Python相關的配置有問題,可能會遇到以下的問題:

CXX/LD -o .build_release/tools/upgrade_net_proto_text.bin
CXX/LD -o .build_release/examples/siamese/convert_mnist_siamese_data.bin
.build_release/lib/libcaffe.so:對‘leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)’未定義的引用
.build_release/lib/libcaffe.so:對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::Status::ToString() const’未定義的引用
.build_release/tools/convert_imageset.o:在函數‘std::string* google::MakeCheckOpString<unsigned long, int>(unsigned long const&, int const&, char const*)’中:
convert_imageset.cpp:(.text._ZN6google17MakeCheckOpStringImiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringImiEEPSsRKT_RKT0_PKc]+0x50):對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/tools/convert_imageset.o:在函數‘main’中:
convert_imageset.cpp:(.text.startup+0x347):對‘google::SetUsageMessage(std::string const&)’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::Status::ToString() const’未定義的引用
.build_release/tools/caffe.o:在函數‘std::string* google::MakeCheckOpString<cudaError, cudaError>(cudaError const&, cudaError const&, char const*)’中:
caffe.cpp:(.text._ZN6google17MakeCheckOpStringI9cudaErrorS1_EEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringI9cudaErrorS1_EEPSsRKT_RKT0_PKc]+0x50):對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/tools/caffe.o:在函數‘std::string* google::MakeCheckOpString<unsigned long, int>(unsigned long const&, int const&, char const*)’中:
caffe.cpp:(.text._ZN6google17MakeCheckOpStringImiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringImiEEPSsRKT_RKT0_PKc]+0x50):對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/tools/caffe.o:在函數‘main’中:
caffe.cpp:(.text.startup+0x53):對‘google::SetVersionString(std::string const&)’未定義的引用
caffe.cpp:(.text.startup+0x86):對‘google::SetUsageMessage(std::string const&)’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::Status::ToString() const’未定義的引用
.build_release/tools/extract_features.o:在函數‘std::string* google::MakeCheckOpString<int, int>(int const&, int const&, char const*)’中:
extract_features.cpp:(.text._ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc]+0x50):對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/tools/extract_features.o:在函數‘std::string* google::MakeCheckOpString<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*)’中:
extract_features.cpp:(.text._ZN6google17MakeCheckOpStringImmEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringImmEEPSsRKT_RKT0_PKc]+0x51):對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::Status::ToString() const’未定義的引用
.build_release/tools/compute_image_mean.o:在函數‘std::string* google::MakeCheckOpString<int, int>(int const&, int const&, char const*)’中:
compute_image_mean.cpp:(.text._ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc]+0x50):對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/tools/compute_image_mean.o:在函數‘std::string* google::MakeCheckOpString<unsigned long, int>(unsigned long const&, int const&, char const*)’中:
compute_image_mean.cpp:(.text._ZN6google17MakeCheckOpStringImiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringImiEEPSsRKT_RKT0_PKc]+0x50):對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/tools/compute_image_mean.o:在函數‘main’中:
compute_image_mean.cpp:(.text.startup+0x172):對‘google::SetUsageMessage(std::string const&)’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::Status::ToString() const’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)’未定義的引用
.build_release/lib/libcaffe.so:對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::Status::ToString() const’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)’未定義的引用
.build_release/lib/libcaffe.so:對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::Status::ToString() const’未定義的引用
.build_release/examples/siamese/convert_mnist_siamese_data.o:在函數‘convert_dataset(char const*, char const*, char const*)’中:
convert_mnist_siamese_data.cpp:(.text+0x4cf):對‘leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)’未定義的引用
.build_release/examples/siamese/convert_mnist_siamese_data.o:在函數‘std::string* google::MakeCheckOpString<unsigned int, int>(unsigned int const&, int const&, char const*)’中:
convert_mnist_siamese_data.cpp:(.text._ZN6google17MakeCheckOpStringIjiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIjiEEPSsRKT_RKT0_PKc]+0x50):對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/examples/siamese/convert_mnist_siamese_data.o:在函數‘std::string* google::MakeCheckOpString<unsigned int, unsigned int>(unsigned int const&, unsigned int const&, char const*)’中:
convert_mnist_siamese_data.cpp:(.text._ZN6google17MakeCheckOpStringIjjEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIjjEEPSsRKT_RKT0_PKc]+0x50):對‘google::base::CheckOpMessageBuilder::NewString()’未定義的引用
.build_release/lib/libcaffe.so:對‘leveldb::Status::ToString() const’未定義的引用
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target ‘.build_release/tools/compute_image_mean.bin’ failed
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
make: *** [.build_release/tools/compute_image_mean.bin] Error 1
make: *** 正在等待未完成的任務…
Makefile:637: recipe for target ‘.build_release/tools/caffe.bin’ failed
make: *** [.build_release/tools/caffe.bin] Error 1
Makefile:637: recipe for target ‘.build_release/tools/extract_features.bin’ failed
make: *** [.build_release/tools/extract_features.bin] Error 1
Makefile:637: recipe for target ‘.build_release/tools/upgrade_solver_proto_text.bin’ failed
make: *** [.build_release/tools/upgrade_solver_proto_text.bin] Error 1
Makefile:637: recipe for target ‘.build_release/tools/upgrade_net_proto_binary.bin’ failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1
Makefile:637: recipe for target ‘.build_release/tools/convert_imageset.bin’ failed
make: *** [.build_release/tools/convert_imageset.bin] Error 1
Makefile:637: recipe for target ‘.build_release/tools/upgrade_net_proto_text.bin’ failed
make: *** [.build_release/tools/upgrade_net_proto_text.bin] Error 1
Makefile:642: recipe for target ‘.build_release/examples/siamese/convert_mnist_siamese_data.bin’ failed
make: *** [.build_release/examples/siamese/convert_mnist_siamese_data.bin] Error 1

如果使用Python2版本就會有以上的問題,如果我改爲 python3版本,即

PYTHON_INCLUDE := /usr/include/python3.5m \
                   /usr/lib/python3.5/dist-packages/numpy/core/include

就發現沒有問題了。我係統裏面兩個版本都安裝有的,可能是默認使用python2的問題吧。

暫且記錄至此,一些常見小問題,在我的caffe安裝博客裏面也有記錄總結,可參考解決,祝你一次成功~

您的支持,是我不斷創作的最大動力~

歡迎點贊關注留言交流~

深度學習,樂此不疲~

個人微信公衆號,更多精彩,歡迎關注~
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章