【深度学习】Caffe中的Protobuf版本问题

机器用的人一多,各种环境就容易被搞乱。今天突然有个妹子告诉我caffe跑崩了,可我一年前明明跑的好好的。。。


protobuf版本冲突

报错的问题如下:
This program requires version 3.6.0 of the Protocol Buffer runtime library, but the installed version is 2.6.1. Please update your library. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in “google/protobuf/descriptor.pb.cc”.)

大意就是protobuf 2.6.1的版本太低了,要升级到3.6.0(没想到一年都升级这么快了?)。

找了github上的几个issue
https://github.com/BVLC/caffe/issues/5711
https://github.com/BVLC/caffe/issues/6359
试了一下,意思是都说让pip install protobuf==3.6.0,这种不靠双手编源码的方式总觉得不靠谱,反正我也没成功。

于是乖乖地,从github上的release下了3.6.0的代码(具体步骤和下面要编的3.3.0一样)开始编译,地址
(https://github.com/google/protobuf/releases/download/v3.6.0/protobuf-all-3.6.0.tar.gz),编译没问题,最后make check的时候报test源码不存在,反正编都编过了,直接

sudo make install
sudo ldconfig
protoc --version

出来版本是3.6.0,protobuf看样子是安装成功了,转去重编caffe。
到了caffe的目录,还是按原来的cmake方式编译,记得以前没报过错,但这次报错了,看了一下信息
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.

说是要C++11支持,于是转到CMakeLists.txt里加一句

set(CMAKE_CXX_STANDARD 11)

上面那个问题不存在了,但是caffe这个时候编译出来了一大堆错误。。。看的脑壳疼,想了一想原来编caffe的时候CMakeLists里没这句也编译过了,感觉是protobuf 3.6.0这货用了C++11什么高级特性带进来的问题。
感觉这样下去要踩坑不断了,回到最初的报错问题上,它说我的protobuf版本低了要用3.6.0,现在3.6.0出来这么一堆错误,我还是降点版本吧3.3.0。


步入正途

先把依赖装一下

sudo apt-get install autoconf automake libtool curl make g++ unzip

下载protobuf 3.3.0的代码,解压

wget https://github.com/google/protobuf/archive/v3.3.0.zip
unzip protobuf

进目录编译

cd protobuf-3.3.0/
./autogen.sh
./configure
make
make check

最终出来下面这个就是check通过了

===============================================================
Testsuite summary for Protocol Buffers 3.3.0
===============================================================
# TOTAL: 7
# PASS:  7
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
===============================================================

然后安装(sudo是直接装在机器的python下的,自己用anaconda的看准了装在哪再install)

sudo make install
sudo ldconfig
protoc --version

出来的是libprotoc 3.3.0,就说明protobuf已经装好了。

回到caffe目录,注掉原来加的C++11那句开始编译,编译通过,ldd build/tools/caffe 看protobuf也已经成功链接上去了,感觉这波稳了,满怀欣喜开始跑一波代码!
啪!脸打的啪啪响,又出现一样的问题,但是这次可以说是精准打脸了,上面那个问题我再贴一遍:
This program requires version 3.6.0 of the Protocol Buffer runtime library, but the installed version is 3.3.0.

caffe一本正经地告诉我,你装了3.3.0很好,但是我要的是 3.6.0。
想了一下为什么caffe总问我要3.6.0,然后看了下pip的list,里面装了个protobuf 3.6.0,感觉应该是这个造成的。

sudo pip uninstall protobuf

卸掉了pip里的 protobuf 3.6.0,然后又开始跑代码,这次报错

no module named google.protobuf.internal

很明显啊,是原来装在pip里的protobuf 3.6.0占用了caffe的python接口,现在只需要进protobuf 3.3.0的python文件夹把3.3.0的python接口编译安装下就OK了。

cd protobuf-3.3.0/python/
python setup.py build 
python setup.py install 
python setup.py test

这下import caffe没问题,跑代码也成功了,又获得了一张好人卡。

  • 6
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Caffe是一个深度学习框架,它依赖于protobufProtocol Buffers)。目前,Caffe可以使用protobuf 3.6.0来编译。因此,如果你想将Caffe与TensorFlow一起使用,你需要调整依赖项版本,确保使用的是protobuf-3.6.0版本来编译Caffe。 关于protobuf版本,你提到了一个问题与相关的引用内容。你提到Caffe装了3.3.0版本,但你需要的是3.6.0版本。你通过pip的list命令查看了已安装的包,发现安装了protobuf 3.6.0。为了满足你的需求,你打算卸载protobuf 3.6.0。 综上所述,Caffeprotobuf版本相关。Caffe可以使用protobuf 3.6.0来编译,并且你可以通过卸载安装了的protobuf 3.6.***<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Caffe,protobuf 编译安装](https://blog.csdn.net/Tosonw/article/details/91043145)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [【深度学习CaffeProtobuf版本问题](https://blog.csdn.net/phdsky/article/details/80994090)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值