TensorFlow protobuf 版本不匹配 [英] TensorFlow protobuf version mismatch

查看:215
本文介绍了TensorFlow protobuf 版本不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过 virtualenv 安装了 TensorFlow.而且效果很好.

I've install TensorFlow via virtualenv. And it works well.

现在我想使用 C++ 加载模型并进行预测.但是由于 protobuf 版本不匹配,我无法编译我的程序.错误如:

Now I want to load model using C++ and do prediction. But I fail to compile my program because of protobuf version mismatch. Error like:

tensorflow/core/framework/device_attributes.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
 #error This file was generated by an older version of protoc which is
  ^
tensorflow/core/framework/device_attributes.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
 #error incompatible with your Protocol Buffer headers.  Please
  ^
tensorflow/core/framework/device_attributes.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
 #error regenerate this file with a newer version of protoc.

在虚拟环境中:

$ pip show protobuf
Name: protobuf
Version: 3.4.0
Summary: Protocol Buffers

在外壳中:

$ protoc --version
libprotoc 3.4.0

我的环境中曾经有 protobuf-2.6.1,但现在升级到 3.4.0.

I used to have protobuf-2.6.1 in my environment but now upgrade to 3.4.0.

Ubuntu 16.04

ubuntu 16.04

推荐答案

问题在于 TensorFlow 编译过程使用了自己的协议缓冲区分布.从 TensorFlow v1.3.0 开始,这个发行版是 protocol buffers 3.3.0.如果您想将自己的 C++ 代码与 TensorFlow 生成的头文件混合使用,则需要使用完全相同的版本(或者只需使用脚本来使用 Bazel 下载的发行版).

The problem is that the TensorFlow compilation process uses pulls its own distribution of protocol buffers. As of TensorFlow v1.3.0, this distribution is protocol buffers 3.3.0. If you want to mix your own C++ code with TensorFlow generated headers, you need to use that exact same version (or simply use a script to use the distribution downloaded by Bazel).

另一种选择是使用您自己的protoc 从原始消息描述文件中生成您自己的标头.

Another alternative is to generate your own headers with your own protoc from the original message description files.

TensorFlow 使用的库版本目前 (TF v1.9) 定义在 tensorflow/workspace.bzl.原则上,只要它与 TensorFlow 和所有其他依赖项兼容,就应该可以生成 TensorFlow 的自定义版本,并在那里更改它的特定所需版本的库(请注意,出于源代码中解释的原因,有是 Protocol Buffers 的三个 HTTP 存档,protobuf_archivecom_google_protobufcom_google_protobuf_cc,因此您需要修改其中三个).

The version of the library used by TensorFlow is currently (TF v1.9) defined in tensorflow/workspace.bzl. In principle, it should be possible to produce a custom build of TensorFlow with a particular desired version of the library changing it there, as long as it is compatible with TensorFlow and every other dependency (note that, for reasons explained in the source, there are three HTTP archives for Protocol Buffers, protobuf_archive, com_google_protobuf and com_google_protobuf_cc, so you would need to modify the three of them).

这篇关于TensorFlow protobuf 版本不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆