1. 程式人生 > >編譯caffe時關於protobuf版本不同的問題

編譯caffe時關於protobuf版本不同的問題

首先安裝caffe的時候Python的版本可選系統自帶的Python2.7或者Python3.5,也可以使用anaconda中的Python版本,對應的Makefile.config中的Python路徑對應的改變。

安裝protobuf的方法也有好幾種:

sudo apt-get install libprotobuf-dev protobuf-compiler  #Linux系統級的安裝
sudo pip install google protocol  #python2.7版本的安裝
sudo pip3 install google protocol  #python3.5版本的安裝
conda install protobuf  #anaconda版本的安裝

檢視系統中已安裝的protobuf:

whereis protoc  #檢視那些路徑下安裝了protobuf
which protoc  #檢視預設選用的protobuf
protoc --version  #檢視當前預設的protobuf的版本
sudo protoc --version  #檢視系統的protobuf的版本

所以在編譯caffe如果報的錯關於Google或者protobuf的,例如:

.build_release/src/caffe/proto/caffe.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is  
error: #error incompatible with your Protocol Buffer headers. Please update  
ImportError: No module named 'google'
問題往往存在於系統上存在多個protobuf的版本,而系統預設的版本不能滿足編譯caffe的要求,這個時候我們可以修改makefile檔案的這兩行,改為自己希望用的版本目錄,例如改為使用系統的:
$(Q)protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_BUILD_DIR) $<
$(Q)protoc --proto_path=$(PROTO_SRC_DIR) --python_out=$(PY_PROTO_BUILD_DIR) $<
改為
$(Q)/usr/bin/protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_BUILD_DIR) $<
$(Q)/usr/bin/protoc --proto_path=$(PROTO_SRC_DIR) --python_out=$(PY_PROTO_BUILD_DIR) $<