1乞巧、 nvcc fatal : Unsupported gpu architecture 'compute_20'
Makefile:594: recipe for target '.build_release/cuda/src/caffe/layers/bnll_layer.o' failed
make: *** [.build_release/cuda/src/caffe/layers/bnll_layer.o] Error 1
caffe 編譯時(shí)出現(xiàn)nvcc fatal : Unsupported gpu architecture 'compute_20'当犯,原因是Makefile.config中CUDA_ARCH的配置問題珊肃,更改Makefile.config, 將 compute_20 所在的兩行注釋掉重新編譯即可蜂怎。
# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
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
2倦西、protobuf版本問題
caffe編譯報(bào)錯(cuò):fatal error: google/protobuf/port_def.inc: No such file or directory
原因是protobuf版本問題倍宾。由于我安裝了anaconda耳标,anaconda安裝了更高版本的protobuf:protobuf.3.11醇坝,而在編譯時(shí)makefile文件調(diào)用的是anaconda下的protobuf,而不是系統(tǒng)下的protobuf2.6次坡。以前遇到protobuf問題時(shí)呼猪,在編譯時(shí)有問題則下載conda下的protobuf,但在caffe使用過程中有時(shí)候又需要protobuf.3砸琅,則又安裝protobuf.3宋距,麻煩也很亂。其實(shí)可以直接修改Makefile文件即可症脂,在編譯時(shí)調(diào)用系統(tǒng)的protobuf2.6版本谚赎,后續(xù)有需要?jiǎng)t使用anaconda的protobuf.3淫僻。
修改Makefile:
修改以下兩行,使其調(diào)用系統(tǒng)的protobuf壶唤,這里筆者的系統(tǒng)protobuf路徑為/usr/lib/protoc
$(Q)protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_BUILD_DIR) $<
$(Q)protoc --proto_path=src --python_out=python $<
$(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h : \
$(PROTO_SRC_DIR)/%.proto | $(PROTO_BUILD_DIR)
@ echo PROTOC $<
#$(Q)protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_BUILD_DIR) $<
$(Q)/usr/lib/protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_BUILD_DIR) $<
$(PY_PROTO_BUILD_DIR)/%_pb2.py : $(PROTO_SRC_DIR)/%.proto \
$(PY_PROTO_INIT) | $(PY_PROTO_BUILD_DIR)
@ echo PROTOC \(python\) $<
#$(Q)protoc --proto_path=src --python_out=python $<
$(Q)/usr/lib/protoc --proto_path=src --python_out=python $<
注:我們?cè)谟行枰臅r(shí)候例如對(duì)caffe添加自定義層嘁傀,可能會(huì)修改caffe目錄下 src/caffe/proto/caffe.proto文件,修改后需要重新對(duì)此文件編譯视粮,命令為:
cd src/caffe/proto
protoc -I=./ --cpp_out=./ ./caffe.proto
在編譯時(shí)提示類似 a newer version protobuf... 的錯(cuò)誤(具體提示記不清了)也是由于編譯時(shí)用的版本3的protobuf细办,更換2.6的protobuf編譯即可此文件即可。
3蕾殴、freetype問題笑撞,/usr/lib64/libfontconfig.so.1: undefined symbol: FT_Done_MM_Var
大概是anaconda安裝時(shí)覆蓋了freetype包,導(dǎo)致庫(kù)鏈接改變钓觉,其他包找不到此函數(shù)茴肥。筆者不想卸載相關(guān)包和重新編譯freetype,因此在找到anaconda下相關(guān)的庫(kù)文件(libfreetype.so荡灾、libfreetype.so.6)瓤狐,將其刪除即可,以防萬一批幌,可以備份一下础锐。
cd xxx/anaconda3/lib
mv libfreetype.so libfreetype.so_bk
mv libfreetype.so.6 libfreetype.so.6_bk
編譯完caffe ,使用時(shí)(import caffe)報(bào)錯(cuò)
4荧缘、ImportError: No module named skimage.ioimport caffe.io
File "caffe/io.py", line 2, in <module>
import skimage.io
ImportError: No module named skimage.io
安裝工具包
conda install scikit-skimage
5皆警、No module named google.protobuf.internal
安裝protobuf,
conda install protobuf
6截粗、ImportError: dynamic module does not define module export function (PyInit__caffe)
原因是使用了python3調(diào)用caffe信姓,caffe對(duì)python3支持不好,切換python2.7使用caffe
7绸罗、/usr/bin/ld: cannot find -lxxx
編譯過程中找不到庫(kù)文件意推。-lxxx表示鏈接庫(kù)文件libxxx.so
可能為:系統(tǒng)缺少對(duì)應(yīng)的庫(kù)文件,或者版本不對(duì)珊蟀,也或者庫(kù)文件鏈接錯(cuò)誤或者路徑不對(duì)
如果是前兩種情況菊值,可通過apt-get進(jìn)行安裝:apt-get install libxxx-dev。
如果存在相應(yīng)的庫(kù)文件且版本正確系洛,則使用locate指令定位鏈接文件俊性,并設(shè)置正確的鏈接路徑
example:
- /usr/bin/ld: cannot fine -lxtst 則 apt-get install libxtst-dev
- /usr/bin/ld: cannot lcaffe
在系統(tǒng)中查找該文件,命令為locate libcaffe
若可以查找到描扯,則新建軟連接使其可以鏈接到libcaffe.so
8定页、fatal error: numpy/arratobject.h: No such file or directory
一般都裝的有numpy,大概率是路徑不對(duì)
import numpy as np
np.get_include()
/usr/local/lib/python2.7/dist-packages/numpy/core/include
而makefile.config里PYTHON_INCLUDE:= /usr/include/python2.7
/usr/lib/python2.7/dist-packages/numpy/core/include
果然路徑不對(duì),修改為正確路徑
9绽诚、cudnn.hpp:127:41: error:too few arguments to functino 'cudnnStatus_t cudnnSetPooling2dDe
這是因?yàn)楫?dāng)前版本的caffe的cudnn實(shí)現(xiàn)與系統(tǒng)所安裝的cudnn的版本不一致引起的典徊。
解決辦法:
1.將./include/caffe/util/cudnn.hpp 換成最新版的caffe里的cudnn的實(shí)現(xiàn)杭煎,即相應(yīng)的cudnn.hpp.
- 將./include/caffe/layers里的,所有以cudnn開頭的文件卒落,例如cudnn_conv_layer.hpp羡铲。 都替換成最新版的caffe里的相應(yīng)的同名文件。
3.將./src/caffe/layer里的儡毕,所有以cudnn開頭的文件也切,例如cudnn_lrn_layer.cu,cudnn_pooling_layer.cpp腰湾,cudnn_sigmoid_layer.cu雷恃。
都替換成最新版的caffe里的相應(yīng)的同名文件。
10费坊、fatal error 缺少各種頭文件倒槐,安裝對(duì)應(yīng)的庫(kù)
fatal error:cblas.h: No such file or directory
apt-get install libopenblas-dev
fatal error: 'lmdb' file not found
apt-get install liblmdb-dev